aspose file tools
The moose likes Beginning Java and the fly likes Problem running a program practicing with Arrays and Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Problem running a program practicing with Arrays and Classes" Watch "Problem running a program practicing with Arrays and Classes" New topic
Author

Problem running a program practicing with Arrays and Classes

Brandon Peeples
Ranch Hand

Joined: Jan 06, 2010
Posts: 38
Hello all. I am having a problem running my program. It produces no output and goes on infinitely. I can't figure out what the problem is. Any help spotting anything unusual with my code would be appreciated. Thanks.




EDIT: Added a main method
Joe Boman
Greenhorn

Joined: Dec 10, 2009
Posts: 16
Hello Brandon,
Are you using a debugger? If so have you set breakpoints in your code?
Let us know/thanks
Joe Boman
Greenhorn

Joined: Dec 10, 2009
Posts: 16
It definitely compiles, however I am getting the following error message when I attempt to execute it:

Exception in thread "main" java.lang.NoSuchMethodError: main

A Google of that error message indicates:
"The Java VM requires that the class you execute with it have a main method at which to begin execution of your application. discusses the main method in detail."
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Joe Boman wrote:It definitely compiles, however I am getting the following error message when I attempt to execute it:

Exception in thread "main" java.lang.NoSuchMethodError: main

So which line causes the exception?
Siddhesh Deodhar
Ranch Hand

Joined: Mar 05, 2009
Posts: 117
Dear, your class is public...

public class LetterInventory{}

Where is your main method ?

public static void main(String args[]) ?


Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd : (SCJP 6 [90%] )
Brandon Peeples
Ranch Hand

Joined: Jan 06, 2010
Posts: 38
Thanks for the replies. I should have mentioned the fact that main is in a different class called "LetterInventoryMain.java" . I tried to execute the program from a different class using the object from "LetterInventory.java" . I think I will just make a main method in the class I posted instead. I'll see if I get some output that way. I'll post an update once I try.
Joe Boman
Greenhorn

Joined: Dec 10, 2009
Posts: 16
I think it is looping in the for loop in the class constructor.

Hope it's ok that I dummied up a "main" module and instantiated the class passing it the string "ABCDE". As a result, the for loop is repeatedly building in lower case "abcdeabcde...etc...etc".

I don't know what this class is supposed to do, but ,but I have a feeling that class behavior may not be intended?

Here is the "main" I added at the bottom of the class:
Brandon Peeples
Ranch Hand

Joined: Jan 06, 2010
Posts: 38
I appreciate the feedback Joe. The class is supposed to accept a String and report the amount of letters (in brackets) in the String ignoring the case and all non alphabetic characters. For example:

LetterInventory inventory1 = new LetterInventory("Pizza123");

should produce: "[aipzz]"


Joe Boman
Greenhorn

Joined: Dec 10, 2009
Posts: 16
Sure, NP Brandon,

When I modify main to pass the string "Pizza123" (which does include numbers), the constructor is carrying out the same unfortunate looping behavior. No change in behavior with numbers.

I don't want to provide suggestions on how to fix this, but the problem became more clear to me when I executed it line by line in a debugger. I like to cheat that way

I use BlueJ, but that's only because it is familiar to me.
thanks/Joe
Brandon Peeples
Ranch Hand

Joined: Jan 06, 2010
Posts: 38
Ahhh thanks Joe. I think I'll give the debugger a try. I am currently using Eclipse for the first time. I know there is a debugger and I'll try to use it. I previously used something without a debugger.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Problem running a program practicing with Arrays and Classes
 
Similar Threads
Why is my type unexpected? required variable found value
Created application for the change pattern AAAA AAAB AABA AABB ect
Counting uppercase?
Help with an encoding/decoding program
Counting uppercase? Part 2!