• Post Reply Bookmark Topic Watch Topic
  • New Topic

Netbeans project builds but won't stop running. Task bar is blue and states running but no progress.  RSS feed

 
Quentin Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to Java.

I am running Netbeans IDE 8.2 with Java Platform Standard Edition 8.

I am completing the 'Hello World' first program challenge detailed here: CodeChallenge
Challenge Day 0: Hello, World.

I don't want to issue a spoiler, in case anyone else is doing this, but i have added to the class the line of required code that prints the contents of the variable 'inputString' to stdout.
I have submitted the answer via the online tool which tests the code and the code is correct.

However, on my machine (Windows 7 X64 with set up as above), the code builds successfully but when i run it, it just keeps running and print nothing out.
I can see the task running bar at the bottom turn from green to blue but then it just keeps running and the progress bar doesn't progress.

I have searched the web and followed instructions such as:

uncheck "Compile on save" setting in the project properties (Build -> Compiling).

I have checked my steps against the following:
https://docs.oracle.com/javase/tutorial/getStarted/cupojava/netbeans.html

I am wondering if this is a configuration problem as the code itself appears to be correct.

Any advice greatly appreciated,

Quentin
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try copying the entire code to a text editor and running it from the command line. You shou‍ld find all you need in our FAQ. Does that program terminate? Have you managed to write an infinite loop somewhere? It is difficult to say any more if you haven't show us the code.

And welcome to the Ranch
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

I don't think it would be a problem for you to post your code.  Hello World programs are easy to find online and most challenges rely on the person not checking Google anyway.

If you do post your code, remember to UseCodeTags (that's a link).
 
Quentin Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the welcome.

Here is the code:

 
Quentin Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran with all the shown imports at top and as currently is, with only one not commented out.

Regards,

Quentin
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quentin Harris wrote:. . .
Never mind what people have told you, you never close a Scanner pointing to System.in. Nor anything else pointing to System.in. Nor anything writing to System.out or System.err.

I can see nothing else in that code which will go wrong. There is nothing which will run for ever. Please confirm how you fed the input to NetBeans. I suggest you add the following or similar as line 29:-
System.out.print("Please enter some text to echo: ");
Then you will know to enter something. If you look in the Scanner documentation, you will find that its methods may block until they are given input. Not giving input will cause the execution to wait until you have some input.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quentin Harris wrote:I ran with all the shown imports at top and as currently is, with only one not commented out.

Regards,

Quentin
The only import you need is:-
import java.util.Scanner;
Obviously you will need different imports for different programs.
 
Quentin Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies. I entered code as below taking on board the suggestions. It prints only after i have entered some text to echo and then gives me the hello world followed by the echo text:
'Hello, World!'
<Echo Text>

So i am mystified as to what is going on. I have simply typed the text into a project in NetBeans and executed.

Revised code below:

 
Quentin Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Campbell Ritchie:

As an aside - All the learning materials on this course, i have seen so far, use scanner.close or something similar.

Why is this wrong please?

Many thanks,

Quentin
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you didn't enter the echo text because you didn't see the prompt; maybe the prompt is necessary to open the console to accept the echo text. Don't know. I hardly ever use NetBeans. The console opens automatically on Eclipse and the command line/terminal is always there ready for input.
Try entering text after line 35 with readLine(), maybe your name, and get it to print “Hello, Quentin” instead. Then you will find out why you mustn't close System.in. Any advice in your course to close System.in is mistaken, and that makes me worry a bit about the whole course. You shou‍ld however always close Scanners reading from files etc.
 
Quentin Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for the explanation regarding .close.

The echo text worked fine. I just wasn't sure why the code wasn't running until i made your amendment.

Did it not run because i wasn't passing anything initially via System.in?

As the test required the input of only one code line i'm somewhat bemused.

Q

 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quentin Harris wrote:
Thanks for the explanation regarding .close.

The echo text worked fine. I just wasn't sure why the code wasn't running until i made your amendment.

Did it not run because i wasn't passing anything initially via System.in? . . .
I have tried to answer those questions already. Where I said don't know, maybe somebody else will know. And, “that's a pleasure
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that you needed to click on the Output Window before you started typing your input.  Here's how my Output Window looked just before I typing something in.
NetBeans-HelloWorld-waiting-for-input.png
[Thumbnail for NetBeans-HelloWorld-waiting-for-input.png]
NetBeans Output Window
 
Quentin Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.

It was my lack of knowledge about System.in and the fact the code example given to complete only indicated one line was required.
While true, it meant there was no text indication at the bottom that i should enter something. The program was waiting for me to pass input as mentioned in the comments above.

I did some homework using,  i think, more useful Youtube videos.  These were more explicit with expected terminology, structure and known common newbie mistakes.

Best wishes,

Q
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did they say about structure and newbie mistakes?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!