Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

This method must return a result of type String

 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help to fix the following error.

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
This method must return a result of type String

at ReadIniFile.getCode(ReadIniFile.java:8)
at ReadIniFile.main(ReadIniFile.java:43)

 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code has one compiler error, and the one you mention is not it. Either you must rebuild your source, or you must PostRealCode. My guess is the former.
 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Your code has one compiler error, and the one you mention is not it. Either you must rebuild your source, or you must PostRealCode. My guess is the former.


You are right!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Unresolved compilation problem" indicates that you have multiple source files and that they are not in sync: you have class files somewhere from a previous version of the source code. The solution is to delete these old class files and recompile all the source code.
 
Sundeep Gupta
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, method getCode must be static
 
Mina Daoud
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only error i can see is that method getCode should be declared static. when i changed it the code worked fine!
 
Mos Jeff
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sundeep Gupta wrote:Also, method getCode must be static


or In main you could create a ReadIniFile object and then make a call to the getCode method from that object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic