• Post Reply Bookmark Topic Watch Topic
  • New Topic

nothing happens when code runs  RSS feed

 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your main() method?
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry i don't know what you mean by a "main method". 
do you mean "public void run". Or do you mean private int. fnum/snum
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never used the acm package before, but according to the documentation, ConsoleProgram extends Program, and the Program documentation says
Every application must either contain a "Main-Class" entry in its manifest file or include a main method that looks like this, where MyClass is the name of the program class:

     public static void main(String[] args) {
         new MyClass().start();
      }

All of your readInt() lines are outside any methods, so are seen as instance variable declarations with initializations, which will executed just before the body of the constructor of your class, but you have not created any instances of your class anywhere.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Danny Alphones wrote:Sorry i don't know what you mean by a "main method". 
do you mean "public void run".


The main() method is what is called when you run a Java application.  And no... that is *not* the run() method.

Henry
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the program extends a class called ConsoleProgram.  I suspect that's the class that provides the main() method that you've been asked about. I also suspect that class calls the run() method.  If this is so, then your program does nothing because your run() method does nothing.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If my suspicions were right, it would have been easier to figure that out if you had written this:

The @Override annotation would have been a clue that the run() method was something that was inherited from the superclass. Notice also blank lines around the method create visual separation. That makes the code easier to read.
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my new code but still nothing happens
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still don't have a main method. See Fred Kleinschmidt's post up about 4-5.

Also, you should paste your code between the code tags...not after both of them.
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger but Junilu Lacar said that my main class is in "ConsoleProgram" witch is probably where my main method() is.
by the way i have run this same class before and everything ran but the code wasnt correct so a made modifications and then when i came to run my code nothing shows up.
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say nothing happens, do you actually mean an empty Applet Viewer window is displayed, but your are not prompted to enter any data, and nothing printed?

 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no when i say nothing i mean absolutely nothing shows up .
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you running the program - from command line, using an IDE, some type of launcher?
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im using eclipse 3.2 on java 1.6 .
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try this to run from Eclipse:
  - right-click on source file (FindRange.java)
  - select Run As
  - select Java Applet

I tried with your code and I do get the applet to start.
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for some reason i cant right click the source tab and when i left click it it does not show the name of my class.
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
never mind, i managed to run it as an applet which is better then nothing but it still did not allow me to do anything on the java applet and it gave me this message Warning: Can't read AppletViewer properties file: C:\Users\Danny\.hotjava\properties Using defaults.
 
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can safely ignore the warning about the property file.

I see two problems with your code:
  - you are not printing the value return by your fnum() and snum() methods
  - you are trying to read input before the run() method is  called

Try reading input from within your run method, and print out the values returned by your methods:


 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP (Danny): You could have saved everyone some time if you had said up front that you are:

1. Studying the Stanford online courses
2. Using this ConsoleProgram

This is what we mean by TellTheDetails (←click that link)
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This class is what's providing the main() method for OP's program.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!