This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Could not find the main class. Program will exit. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Could not find the main class. Program will exit." Watch "Could not find the main class. Program will exit." New topic
Author

Could not find the main class. Program will exit.

Matheus Porto
Greenhorn

Joined: Dec 14, 2010
Posts: 2
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
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

Joined: Dec 14, 2010
Posts: 2
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

Joined: Jul 16, 2012
Posts: 86
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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

Joined: Oct 13, 2005
Posts: 37884
    
  22
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Could not find the main class. Program will exit.
 
Similar Threads
please help me to solve the program
could not find the main class
Problem in runnin ant build file from eclipse
how to open run jar file with double click in windows 7 ?
Cannot Run Apache-tomcat 6 on Centos 5.4