• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.OutOfMemoryError: Java heap space

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 7582
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post the complete command you're entering.
 
Andrew Geroge Alexander
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
after looking carefully, i did see i had syntax wrong.. but after correcting that i have 'No ClassDef error'..
 
Andrew Geroge Alexander
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Andrew Geroge Alexander
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

reply
    Bookmark Topic Watch Topic
  • New Topic