File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes java.lang.OutOfMemoryError: Java heap space Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.lang.OutOfMemoryError: Java heap space" Watch "java.lang.OutOfMemoryError: Java heap space" New topic
Author

java.lang.OutOfMemoryError: Java heap space

Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
I am running a program, that will obtain a file (Excel) as input, and create a table from that data obtasined from the excel sheet in MySQL.

For smaller data files it is working great, but now. I tried importing a file that has 50K records and i had a exception "java.lang.OutOfMemoryError: Java heap space"
any way i can use to increase the size?

I went through the internet and i found that by using this:
I will be able to allocate 1GB of space for the VM. but when i tried to do it in command line i got an error saying,
Error: Could not find or load main class ...

I am not sure how to get over this error can someone help me out here?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Post the complete command you're entering.
Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
I need to also tel that I have designed this program using JDK 7.1 and am using poi.apache library to import into MySQL.
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Sounds like there's something wrong in the command syntax you're trying to run. Check the argument order, or skip any arguments to see the "java" command options.
Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
Hello Tim,

This is what I used.. navigated to the file location(DataFilter is the class/main method name) and

java -Xmx1024m DataFilter
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Make sure you set the classpath properly. Could be as simple as "java -cp . -Xmx1024m DataFilter" assuming that class is not part of a package.
Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
after looking carefully, i did see i had syntax wrong.. but after correcting that i have 'No ClassDef error'..
Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
Am so sorry.. I am a bit new and was not sure what i was doiing.. okay, now let me try to explain again.

DataFilter is the name of the package, from which I am calling other forms(JFrames) inside the package.
I have other components such as 'DisplayArea', 'LoginForm'. So I am calling LoginForm from which DisplayArea is called.

I hope i am making some sense.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Paul Ruban Raj Eugin Francis wrote:
I hope i am making some sense.


You'll make more sense if you copy/paste the exact command you're running, as well as the exact, complete error message. Also indicate what your current working directory is, where the class in question is located, and what package it's in.
Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
I am sorry.. But this is my exact error message,

C:\Users\Paul\Documents\NetBeansProjects\DataFilter\build\classes\datafilter>java -Xmx1024m DataFilter
Exception in thread "main" java.lang.NoClassDefFoundError: DataFilter (wrong name: datafilter/DataFilter)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:476)

DataFilter is the name of the package, in which there are two other classes.

Directory of C:\Users\Paul\Documents\NetBeansProjects\DataFilter\src\datafilter

21/02/2012 16:20 710 DataFilter.java
21/02/2012 16:22 9,712 DisplayArea.form
21/02/2012 16:22 16,737 DisplayArea.java
21/02/2012 12:05 6,626 LoginForm.form
21/02/2012 12:05 7,890 LoginForm.java

Bruno Candido Volpato da Cunha
Greenhorn

Joined: Feb 21, 2012
Posts: 18

Paul Ruban Raj Eugin Francis wrote:I am sorry.. But this is my exact error message,

C:\Users\Paul\Documents\NetBeansProjects\DataFilter\build\classes\datafilter>java -Xmx1024m DataFilter
Exception in thread "main" java.lang.NoClassDefFoundError: DataFilter (wrong name: datafilter/DataFilter)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:476)

DataFilter is the name of the package, in which there are two other classes.

Directory of C:\Users\Paul\Documents\NetBeansProjects\DataFilter\src\datafilter

21/02/2012 16:20 710 DataFilter.java
21/02/2012 16:22 9,712 DisplayArea.form
21/02/2012 16:22 16,737 DisplayArea.java
21/02/2012 12:05 6,626 LoginForm.form
21/02/2012 12:05 7,890 LoginForm.java



You'll need to go to path "C:\Users\Paul\Documents\NetBeansProjects\DataFilter\build\classes", and execute the following command line:
java -Xmx1024m datafilter.DataFilter


Bruno Candido Volpato da Cunha
Oracle Certified Java Programmer 6
Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
You'll need to go to path "C:\Users\Paul\Documents\NetBeansProjects\DataFilter\build\classes", and execute the following command line:
java -Xmx1024m datafilter.DataFilter


Well it worked and did not work, i mean i use the LoginForm to establish the connection to MySQL DB. But it is throwing a SQLException now. I mean I cannot go any further.
Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
is there a way i can hardcode this? I mean i am running the file from JDK, not command line. even if this works in commandline, i cannot everytime run the file from commandline right?
Bruno Candido Volpato da Cunha
Greenhorn

Joined: Feb 21, 2012
Posts: 18

You can create a JAR File (Java Archiver), and put filterdata.Filterdata as your main-class in MANIFEST.MF file.
It's nothing but a Zip File, with your classes.

If you're using an IDE, you can create your JAR File in the Export tools.

What error (SQLException) you are getting?
Paste the entire exception, so we can help you.

Maybe you'll have to put your database jar file in the -classpath parameter.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Paul Ruban Raj Eugin Francis wrote:I am sorry.. But this is my exact error message,

C:\Users\Paul\Documents\NetBeansProjects\DataFilter\build\classes\datafilter>java -Xmx1024m DataFilter
Exception in thread "main" java.lang.NoClassDefFoundError: DataFilter (wrong name: datafilter/DataFilter)

...

DataFilter is the name of the package, in which there are two other classes.

Directory of C:\Users\Paul\Documents\NetBeansProjects\DataFilter\src\datafilter

21/02/2012 16:20 710 DataFilter.java
21/02/2012 16:22 9,712 DisplayArea.form
21/02/2012 16:22 16,737 DisplayArea.java
21/02/2012 12:05 6,626 LoginForm.form
21/02/2012 12:05 7,890 LoginForm.java



You need to run it like this:


Note that it does NOT work "move" package levels from the fully qualified classname to the classpath argument (which is basically what you were tyring to do above).


You have to specify the parent directory of the root of the package structure, and you have to specify the fully-qualified classname (that is, including it's package name).
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Paul Ruban Raj Eugin Francis wrote:is there a way i can hardcode this?


You can create an executable jar, or you can write a simple shell script.

I mean i am running the file from JDK, not command line.


What do you mean by that?

even if this works in commandline, i cannot everytime run the file from commandline right?


How you distribute and run your app is up to you.
Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
Hello, Thank you all for helping me out.. I am really glad..

@Bruno >> I am getting this error..

C:\>java -Xmx1024m -cp C:\Users\Paul\Documents\NetBeansProjects\DataFilter\build
\classes datafilter.DataFilter
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Paul Ruban Raj Eugin Francis wrote:Hello, Thank you all for helping me out.. I am really glad..

@Bruno >> I am getting this error..

C:\>java -Xmx1024m -cp C:\Users\Paul\Documents\NetBeansProjects\DataFilter\build
\classes datafilter.DataFilter
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver



You need to include the mysql jar on your classpath. Something like

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.OutOfMemoryError: Java heap space