Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could not find the main class. Program will exit.

 
Matheus Porto
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying to run an app but every time I do I get the error: "Could not find the main class. Program will exit."
The console shows me the following:

java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
at comum.ConexaoOracle.<init>(ConexaoOracle.java:21)
at mailNotifica.Notificacao.<clinit>(Notificacao.java:15)
Exception in thread "main"

Does anyone knows what it means ? What are the possible solutions ?

I've set the Main Class on Run > Run Configurations in Eclipse IDE, but still not working.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This message just means that you're loading the Oracle JDBC driver in a static initializer for your main class (mailNotifica.Notificacao is creating an instance of comum.ConexaoOracle, which is trying to load the driver), and because the driver is not being found, Java can't fully load the class and run your main() method. You need to include the Oracle driver jar file on your class path when you run the application.
 
Campbell Ritchie
Sheriff
Posts: 51438
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
Which version of Java did you get this problem with. Handling of classes without main methods is different in Java6 and Java7.
 
Matheus Porto
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all thanks for the answers.

My JDK version is 1.7.0_10 according to "java -version" on console.
My JRE version is (JRE1.6.0_03).


I've downloaded the JDBC driver and added in Java Build Path. Now I'm getting the following..

java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193)
at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:873)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289)
at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1909)
at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1871)
at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:318)
at mailNotifica.Notificacao.buscaTotal(Notificacao.java:55)
at mailNotifica.Notificacao.mandaEmail(Notificacao.java:111)
at mailNotifica.Notificacao.main(Notificacao.java:21)
Erro no método buscaTotal - Classe Notificacaojava.sql.SQLSyntaxErrorException: ORA-00911: invalid character null
java.lang.Exception
at mailNotifica.Notificacao.mandaEmail(Notificacao.java:126)
at mailNotifica.Notificacao.main(Notificacao.java:21)
Erro no método mandaEmail - Classe PontoEstoqueEmailjava.lang.Exception


 
Joe Ridener
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

To give you an example of what might cause this...

When loading from the command line I would often take files that were edited in NetBeans or Eclipse. I would then use the javac command and it would not compile my files into class files, and would tell me that "No Main class found"

The reason for this.. is becuase NetBeans and Eclipse editors at the line at the beginging

package NameOfDirectoryOrJavaPackageYourWorkingIn;

When you try to compile a .JAVA file with this line. It begins searching for a package that it will not find. Therefore, no main class was found. Remove this line and it willl compile you class file for you.

Hope this helps....
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe is addressing the problem you've already solved, and not in a good way: generally all java classes should be defined in a package.

This error message means that the query being sent to the database has a bad character in it -- ie it is not valid SQL. You may need to use the debugger or add logging (print statements) to see what's wrong with the query (unless you can just show it to us here.)
 
Campbell Ritchie
Sheriff
Posts: 51438
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not convinced that will cause either of the two Exceptions we saw. If you have the .class files in the wrong location you tend to get errors like class not found or wrong class name.
Are you sure about the Java versions? You will have problems if you use the Java7 JDK and the Java6 JRE together. If the Java7 JDK appears first in your System PATH, as described here and here, then you will only ever use Java7. If java -version returns 1.7.0_10, then you have probably set your PATH correctly.
As for the SQL exception: don’t know. Find the documentation (?Oracle) and see what ORA-0911 means.
Try to work out from the line numbers which query it was, or run every SQL query at the command line, rather than via a Java front‑end, and see which produces an Exception. Show is the full query, characters like ã included.

I think this discussion would now fit better in our databases fora. Moving it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic