Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

nothing happens when code runs

 
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Bartender
Posts: 732
10
  • 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: 732
10
  • 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.
 
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
Marshal
Posts: 15894
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • 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
Marshal
Posts: 15894
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • 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
 
lowercase baba
Posts: 12893
63
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.
 
Marshal
Posts: 3185
468
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • 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
Marshal
Posts: 3185
468
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • 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
Marshal
Posts: 3185
468
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • 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
Marshal
Posts: 3185
468
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • 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
Marshal
Posts: 15894
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • 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
Marshal
Posts: 15894
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This class is what's providing the main() method for OP's program.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic