aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes another kind of Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "another kind of Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space" Watch "another kind of Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space" New topic
Author

another kind of Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
Hi,

I'm sorry, I don't speak english very well :-S (but if you want to speak french, I'll say: good idea ! )
I'll even try to introduce my problem to you:
I've this message : Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
after compilation of the following lines:
(In fact, it works with little pics, but not bigs (10MB), and I need it works with big pics)
Is there somebody who can explain to me how resolve this problem?
I want to display a pic (a map in fact) and, by drag and drop, move this pic (as in mappy, or google map, etc...)
there arer some french words in the code:
ecouteur = listener
image = picture
creerMiniature = createLittlePic
later, when this problem will resolved, I'll try to zoom on the picture with the wheel of the mouse....I'm not out of the wood....
thank you very much !!



---------------------------------
New beginner in java...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38756
    
  23
Please use the code button; it makes the code easier to read.
Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
it's done
sorry
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38756
    
  23
Thank you.

Are you enlarging the images? Are you aware of the options (xmx and xms) for setting heap sizes for the java tool? It is worth trying increasing heap size. I am afraid I couldn't execute your code because one of the packages was missing.

Anybody else able to help?
Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
I've fixed this code to make it running (remember about putting any image in subdirectory Images/images.jpg) but It works fine.. I have loaded 12MB image and javaw.exe process took only 35MB of memory... (I've tried to resize it many times and to do a lot of dragging but I couldn't exceed that number; no OutOfMemoryError occured). I've even run it with parameters -Xms8m -Xmx40m but still no error Sylvain, post code that cause problems or - like Campbell Ritchie suggested - run Your code like this: java -Xms128m -Xmx512m MinFrame to get rid of OutOfMemoryError
Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
thanks for your help Bartek, but I've a problem with Netbeans, it cannot find symbol class GroupLayout in: import javax.swing.GroupLayout;



Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
Bartek, you said: "run Your code like this: java -Xms128m -Xmx512m MinFrame to get rid of OutOfMemoryError "
but I can't do that with windows? it's only with shell in linux ?
Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
1. You have used org.jdesktop.layout.GroupLayout and I don't know whats that... the standard GroupLayout is in javax.swing.GroupLayout so I've changed to it - if org.jdesktop.layout.GroupLayout only fits You, use Your version. I've changed it only to make it running on my computer but I don't think that this cause a problem.
2. It's not only linux shell windows also have "shell"... cmd.exe - simply run command line, navigate to directory with your classes and run with these parameters. You can also create a batch file to run this by doubleclicking - create file called ex. "run.bat" and put this inside: (put bat file with Your classes and run)
3. If You are using eclipse You can specify parameters for VM by RightClikOnProject -> Run -> RunConfigurations -> Arguments -> VMarguments
If You are using NetBeans I can't help You beacause I don't like this IDE and I simply don't know
4. If Your application is windows-only You can use exe-wrapper like launch4j to set VM parameters and create single exe file
Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15

I've changed my JDK from 1.5 to 1.6, and it works for little pictures but still not bigger ! :-S



init:
deps-jar:
compile-single:
run-single:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:58)
at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleModel.java:397)
at java.awt.image.Raster.createWritableRaster(Raster.java:938)
at javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifier.java:1056)
at javax.imageio.ImageReader.getDestination(ImageReader.java:2879)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:943)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:915)
at javax.imageio.ImageIO.read(ImageIO.java:1422)
at javax.imageio.ImageIO.read(ImageIO.java:1282)
at Nexter3.MainFrameInternet.<init>(MainFrameInternet.java:50)
at Nexter3.MainFrameInternet.main(MainFrameInternet.java:214)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)


And I've seen another little problem:
if the picture is too big to be initially displayed in the screen, when dragging the picture in the purpose to see further the limit of the screen, the picture remain cut: it's white...
How can I resolve that?
Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
so I'm going to try what you said with cmd... :-)
Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
I've tried to execute with:
java -Xms128m -Xmx512m MainFrame.class

In fact, DOS answer: could not find the main class: MainFrame.class
but i'm in the good directory, where MainFrame.class is ! I've set the path to the jdk, i've compiled the .java to obtain the .class
what could I have forgotten?
Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
well.. if You want to run a class You don't give extension
it should be: "java -Xms128m -Xmx512m MainFrame"
NOT "java -Xms128m -Xmx512m MainFrame.class"
also if You've put classes inside some packages You have to open only project class directory and run it like this "java -Xms128m -Xmx512m com.myPackage.MainFrame" (if MainFrame is inside com.myPackage)
Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
even with the package name before as you shown to me, and without the .class the answer is the same...
Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
post here directory structure otherwise I can only guess what's wrong..
Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
I found an error I made: i've written:

cd C:\Users\yggdrasylv\Documents\NetBeansProjects\DesktopApplication3 - Copie\src\Pack3
after that I 've writen:
java -Xms128m -Xmx512m Pack3.MainFrame

it seems that i would have to go there:
cd C:\Users\yggdrasylv\Documents\NetBeansProjects\DesktopApplication3 - Copie\src

in Pack3 i've MainFrame.class and MainFrame.java

now the error is:
exception in thread "main" javax.imageIO.read.IIOException: can't read input file

but i've past the picture in
C:\Users\yggdrasylv\Documents\NetBeansProjects\DesktopApplication3 - Copie\src\Pack3
and i've past the image in
C:\Users\yggdrasylv\Documents\NetBeansProjects\DesktopApplication3 - Copie\Images

Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
javax.imageIO.read.IIOException: can't read input file - it means it can't load the image

I assume that You have Your classes in C:\Users\yggdrasylv\Documents\NetBeansProjects\DesktopApplication3 - Copie\src\
So You should also copy Images folder there.. it shoud look like this:
Folder with images: C:\Users\yggdrasylv\Documents\NetBeansProjects\DesktopApplication3 - Copie\src\Images\
Folder with classes: C:\Users\yggdrasylv\Documents\NetBeansProjects\DesktopApplication3 - Copie\src\
Package folder only: C:\Users\yggdrasylv\Documents\NetBeansProjects\DesktopApplication3 - Copie\src\Pack3
now navigate to C:\Users\yggdrasylv\Documents\NetBeansProjects\DesktopApplication3 - Copie\src\ and type: java -Xms128m -Xmx512m Pack3.MainFrame
it must run now!
Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
it works ! :-) thank you very much !!!
and i've tried with big pictures, it works too ! :-D

what means -Xms128m -Xmx512m in fact?
and is this the only one way to do that with the .bat ?

.... You may not be able to answer if you don't know netbeans... :-S

there still a little problem: the big picture is cut when I move it... have you got any idea about the way i can correct that?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38756
    
  23
You can find out about the -Xms and -Xmx tags here.
Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
Sylvain Prodo wrote:(...)there still a little problem: the big picture is cut when I move it... have you got any idea about the way i can correct that?
I would try putting JPanel on which You are painting inside JScrollPane... but I'm not sure about this... check this example - it should help You with this problem.

Sylvain Prodo wrote:what means -Xms128m -Xmx512m in fact?
I won't tell You - Campbell Ritchie gave You the link to documentation, You don't have to read everything... just options You want to use: -Xmsn and -Xmxn

Sylvain Prodo wrote:and is this the only one way to do that with the .bat ?
No.. I hope that it is posible to pass argument to VM inside jar-file (in manifest file?) but I have too small knowledge on this topic
Try to find with google how to pass VM arguments under NetBeans
@edit: (in case You couldn't find it for NetBeans: RightClickOnProject -> SetConfiguration -> Customize... -> VM Options)
Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
i've find how pass arguments, it works ! :-) thanks !

http://netbeans.developpez.com/faq/?page=DeveloppementJ2SE

but still a problem with the panel'm trying many methods.
Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
Sylvain Prodo wrote:but still a problem with the panel'm trying many methods.

I think that this example can help You: LINK
When You put MapPane on JScrollPane You should be able to see whole image (with scrolling). Then You can implement dragging to it and hide scrollbars.
Sylvain Prodo
Greenhorn

Joined: Feb 26, 2009
Posts: 15
Thanks Bartek ! but I don't want any scroll bar in my frame... I have to move inside the entire picture only by drag and drop :-/
I've tried to make a zoom with the wheel of the mouse, it averagely works, but the picture is zoomed at its left corner instead of be zoomed at its center (the center of the actual screen).
I'm going to create another subject for that: here it beginns to be inappropriate with:
"another kind of Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space" I consider that this subject is resolved.
Konstantin Andry
Greenhorn

Joined: Apr 27, 2009
Posts: 9
"java -Xms128m -Xmx512m"

How to use these tags in applet?

I have signed code in jar archive
and i have html file for start:
Konstantin Andry
Greenhorn

Joined: Apr 27, 2009
Posts: 9
RESOLVED:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: another kind of Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space