• Post Reply Bookmark Topic Watch Topic
  • New Topic

This code is not executing: what's the problem?  RSS feed

 
Mard Butler
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Art, welcome to CodeRanch!

Well, having a main method in a nested class definitely isn't conventional. How do you run the program? What error messages do you get?
 
Mard Butler
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I run it like this

javac ListPool.java
java ListPool

Output is :
Error: Main method not found in class ListPool, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because ListPool doesn't have a main method. The main method belongs to ListPool.MyLinkedList.Node, which is a very questionable way to organize your classes.

Why don't you put MyLinkedList in a separate .java file, and make the main method part of ListPool directly?
 
Mard Butler
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

Though you have told its questionable way of executing the code but i am just having a class inside a class which has a main method.
I do not think i am doing something fundamentally wrong which is preventing the compiler to recognize the main method.
Is there a way i can debug the code and see how compiler sees this ?

rgds,

 
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
Mard Butler wrote:
I do not think i am doing something fundamentally wrong which is preventing the compiler to recognize the main method.
Is there a way i can debug the code and see how compiler sees this ?


The compiler recognizes the main() method declaration fine. And created a static main() method in the protected nested Node class of the public nested MyLinkedList class of the top level class named ListPool.

Mard Butler wrote:I run it like this

java ListPool


This tries to execute a static main() method of the top level class named ListPool. The compiler never created such a method, because you never declared one.

Henry
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So might execute the code you want.
However the $ syntax is not necessarily standard.

Normally you would want the main method in a top level class.
Even if you have to create a LinkedListRunner class to put 'main' in.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!