• Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue related to object use  RSS feed

 
Tiberius Marius
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I don't understand why i get the error when i try to run it :

Exception in thread "main" acm.util.ErrorException: Cannot determine the main class.
at acm.program.Program.main(Program.java:1358)

I m learning to use objects , conceptually did i use them incorrectly from the problem at hand (ask for hexadecimal numbers as string and convert them to decimal ?
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.oxfordmathcenter.com/drupal7/node/46

Honestly, I don't think it's a good idea to use external libraries when you're still learning the basics. They just prevent you from learning the language itself. you should probably get rid of ACM.

As for parsing a hexadecimal number, you've made a small mistake. The base of the number is mostly a property of String representations of that number. You shouldn't have an integer variable called decimalNumber, because ints don't know anything about the decimal system. Everything is stored as binary. When you print an integer, their binary value is converted to a String that represents the number as base 10. To parse a String, you should specify the radix of the input String, because Java can't tell from looking at the String. The value will always be parsed to whatever internal system the machine uses (binary).

Also, please put your fields at the top of the class, because that's where people look for them.
 
Tiberius Marius
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan thanks for pointing out the issues with the incorrect method parameters and my understanding of it .I started learning programming with the book The Art and Science of Java (that uses ACM) and i m more then half way in so i ll have to stick to the ACM libraries until i finish it , after that no more ATM .
I remade the class without using a constructor and it works(first code wall) . Also i added bellow the old one with a bit of chances and cleaning but i still get the error bellow and i still don't know how to make it work... any input ?

Exception in thread "main" acm.util.ErrorException: Cannot determine the main class.
at acm.program.Program.main(Program.java:1358)







The old way that still does not work :

 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is lacking the main method to qualify it as a main class... add the following:

 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rico, that will override the standard behavior of the ACM library, which is exactly the thing Tiberius doesn't want to happen.

Tiberius, please explain in detail how you are running the program.
 
Tiberius Marius
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m writing the code in Gedit (linux text editor) and then saving it as <name of class>.java and running the programs using the linux terminal .

I m setting the path of the terminal to the location of both the acm library and the file created with the gedit (saved as .java) and then to create the .class file i use the command :

javac -classpath acm.jar Conv2.java


and then to run the code :

java -cp .:acm.jar Conv2


the name of the file in this case is Conv2.java
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess would be that in order to create an instance of the class that contains the run method, the ACM code requires that class to have a no-arg constructor.
Becuase you've added a constructor that takes a String argument, you no longer have a no-arg constructor and so ACM can't create an instance of your class.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've did some research on the library and Joanne is correct... you must have a no-arg constructor for ACM to create an instance of your class...

Screenshot-from-2014-04-27-10-03-46.png
[Thumbnail for Screenshot-from-2014-04-27-10-03-46.png]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!