File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help!!! I write the code it compiled but it can't run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help!!! I write the code it compiled but it can Watch "Help!!! I write the code it compiled but it can New topic
Author

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

pigmario kurth
Greenhorn

Joined: May 12, 2006
Posts: 2
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

Joined: Aug 31, 2004
Posts: 11343

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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
pigmario kurth
Greenhorn

Joined: May 12, 2006
Posts: 2
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

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Oct 13, 2005
Posts: 37907
    
  22
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help!!! I write the code it compiled but it can't run
 
Similar Threads
I can compile but can't run
Null pointer exception when trying to enter a blank for a response -- how to fix?
Head First Java Ready-Bake Code
Console User Input?
HeadFirstJava - SimpleDotCom