aspose file tools*
The moose likes Beginning Java and the fly likes New to Java and wanting to learn Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "New to Java and wanting to learn" Watch "New to Java and wanting to learn" New topic
Author

New to Java and wanting to learn

Kamran Khaen
Greenhorn

Joined: Jan 16, 2010
Posts: 15
Needed help getting a compiler error



new to java, error is

"int cannot be dereferenced" i know its because im trying to display an int as a string but i know theirs a way just need help
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
age is an int variable, a primitive and you can't call a method on a primitive. Since String is smart enough to figure out what to do here, why not simply do:

Kamran Khaen
Greenhorn

Joined: Jan 16, 2010
Posts: 15
bessically, in my assignment ive been asked to add a toString method, which includes the student id, name , age and points. Now the error is saying im "missing a return statement".

and would this method be ok as a toString method or do i have to carry out different codeing?
Siddhesh Deodhar
Ranch Hand

Joined: Mar 05, 2009
Posts: 118
toString() method looks OK. You need to return your String at last because return type of method is String..

public String toString()
{
String StudentInfo = "Student ID: " + idNumber +
"\nName: " + name +
"\nPoints: " + achievementPts +
"\nAge: " + age;
return StudentInfo;
}

well, Welcome to java ranch..You will enjoy java here


Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd : (SCJP 6 [90%] )
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Please do not post in all uppercase. Please read this for more information. I have adjusted to topic title for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kamran Khaen
Greenhorn

Joined: Jan 16, 2010
Posts: 15
Siddhesh Deodhar wrote:toString() method looks OK. You need to return your String at last because return type of method is String..

public String toString()
{
String StudentInfo = "Student ID: " + idNumber +
"\nName: " + name +
"\nPoints: " + achievementPts +
"\nAge: " + age;
return StudentInfo;
}

well, Welcome to java ranch..You will enjoy java here




fanks it worked, just wondering is the to string method spost to print to terminal window?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

"j Blue", please check your private messages for an important administrative matter.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Moving to Beginning Java. And please use a meaningful subject line next time.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: New to Java and wanting to learn