• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Saloon Keeper
Posts: 14260
321
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 14260
321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,

 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Do you pee on your compost? Does this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic