Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help!!! I write the code it compiled but it can't run

 
pigmario kurth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've copy code from Headfirst java book in GameHelper class

import java.io.*;
public class GameHelper {
public String getUserInput(String prompt) {
String inputLine = null;
System.out.print(prompt + " ");
try {
BufferedReader is = new BufferedReader(
new InputStreamReader(System.in));
inputLine = is.readLine();
if(inputLine.length() == 0) return null;
} catch (IOException e) {
System.out.println("IOException: "+e);
}
return inputLine;
}
}
and this is the test code
public class TestHelper {
public static void main (String args[]){
GameHelper helper = new GameHelper();
String guess = helper.getUserInput("enter a number");
}
}
they both compile but when it run it say (I use editplus)
---------- Run ----------
and nothing happen look like it stuck in loop

Did I done something wrong ?
I use jdk1.5.0_06
May be I have to set classpath for use this code?
Please help me!!!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Your code works fine for me (using a simple text editor and command prompt). I even added a println in main to display the guess and verify that it's reading the input correctly.

Are both of these files in the same directory? When you run, are you running TestHelper?

(Note: Please use Code Tags to keep your code indentation showing. )
[ May 12, 2006: Message edited by: marc weber ]
 
pigmario kurth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply marc weber
I've copy the code to notepad and run using command prompt
it work fine propably i set something wrong in editplus so it won't run
anyway Thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pigmario kurth:
...propably i set something wrong in editplus so it won't run...

I'm not familiar with EditPlus, but if you need help configuring that, you could try posting in our IDE forum.
[ May 13, 2006: Message edited by: marc weber ]
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NotePad?
It will work, but there are far better produects available.
I think this website, <a href="http://www.jcreator.com,</a rel="nofollow">" target="_blank">http://www.jcreator.com,[/URL] is right, and you can get JCreatorLE from it, which is a cut-down IDE, used as a Java text editor.
In my opinion it is the best text editor for Java for Windows.
It will do things like putting keywords in different colour, and (most useful of all) matching up pairs of {} and ().

CR
[ May 14, 2006: Message edited by: Campbell Ritchie ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic