Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: ERROR - The method setTypeface(Typeface, int) is undefined for the type String

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ERROR - The method setTypeface(Typeface, int) is undefined for the type String

    this is my code so far, i don't think it accepts the variable 'count' from the other class, but it keeps coming up with this error under
    setTypeFace.
    package com.example;
     
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import android.graphics.Typeface;
    import android.view.View;
     
    public class Message extends ChatApplication{
     
    	@Override
    	public String toString() {
    		return timeFormat.format(time) + "\n" + sender + text + count;
    	}
     
    	Date time = new Date();
    	SimpleDateFormat timeFormat = new SimpleDateFormat ("HH:mm");
     
    	private String text;
    	private String sender = "Carla: ";
    	public int count;
     
    	public void button(){
    		if(count==0){
    			text.setTypeface(Typeface.DEFAULT,Typeface.NORMAL);
    		}
    		else if (count == 1){
    			text.setTypeface(Typeface.DEFAULT,Typeface.ITALIC);
    		}
    		else if (count == 2){
    			text.setTypeface(Typeface.DEFAULT,Typeface.BOLD);
    		}
    	}
     
    	public Message(String text) {
    		super();
    		this.text = text;
    	}
     
    	public String getText() {
    		return text;
    	}
     
    	public Message(int count) {
    		super();
    		this.count = count;
    	}
     
    	public int getCount() {
    		return count;
    	}
     
     
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,355
    Thanks
    182
    Thanked 833 Times in 776 Posts
    Blog Entries
    5

    Default Re: ERROR - The method setTypeface(Typeface, int) is undefined for the type String

    For future reference, please wrap your codes in the code tags.

    See the API for String - does it contain a setTypeface method with those parameters?

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ERROR - The method setTypeface(Typeface, int) is undefined for the type String

    no, i didn't think i needed a method for it, i've used this code before and it's worked fine like this !

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,355
    Thanks
    182
    Thanked 833 Times in 776 Posts
    Blog Entries
    5

    Default Re: ERROR - The method setTypeface(Typeface, int) is undefined for the type String

    Quote Originally Posted by carladessi View Post
    no, i didn't think i needed a method for it, i've used this code before and it's worked fine like this !
    You cannot call a method that does not exists. The text variable is of type String, and it does not contain that method.
    String | Android Developers

Similar Threads

  1. type conversion error
    By Xeenix in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2011, 08:29 PM
  2. Ending a method that has no return type
    By Blehs in forum Java Theory & Questions
    Replies: 3
    Last Post: August 12th, 2011, 02:56 AM
  3. How to shift a String in a rectangle which is type of Canvas
    By elenora in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: April 4th, 2011, 08:39 AM
  4. error: This method must return a result of type int
    By J05HYYY in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 13th, 2011, 05:26 PM
  5. he operator / is undefined for the argument type(s) String, int
    By mtbr00x in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 8th, 2009, 09:34 PM