File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New to Java and wanting to learn

 
Kamran Khaen
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not post in all uppercase. Please read this for more information. I have adjusted to topic title for you.
 
Kamran Khaen
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"j Blue", please check your private messages for an important administrative matter.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Beginning Java. And please use a meaningful subject line next time.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic