Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Unhappy AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

    Hi,

    I have written a java application with different classes. when I instanciate an object of one of this classes in another class, this message appearsException in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space". I checked to instanciate the object in other classes of the same package, I see that in this case there is no error. what might be the reason?

    Regards,


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

    Without posting code its anyone's guess what's going on. Are you reading large files/information into memory? Creating a bucketload of objects? One way to try and alleviate the problem is to increase the default heap size on the command line using the -Xmx parameter (eg java -Xmx512m yourProgram).

  3. #3
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

    this is a code, the problem is with the line in Bold
    package LiveLectureNotes;


    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.KeyEvent;

    public class LecturerArea extends JFrame{

    JTextPane lecturenote;

    private static final long serialVersionUID = 1L;

    public LecturerArea(String Title) {
    super(Title);
    setLayout(new BorderLayout());

    //Create a text pane.
    lecturenote = createTextPane();
    JScrollPane paneScrollPane = new JScrollPane(lecturenote);
    paneScrollPane.setVerticalScrollBarPolicy(
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    paneScrollPane.setPreferredSize(new Dimension(400,750));
    paneScrollPane.setMinimumSize(new Dimension(10, 10));


    //Create a text pane.
    JTextPane searchresult =new JTextPane();
    JScrollPane paneScrollPane1 = new JScrollPane(searchresult);
    paneScrollPane1.setVerticalScrollBarPolicy(
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    paneScrollPane1.setPreferredSize(new Dimension(400,750));
    paneScrollPane1.setMinimumSize(new Dimension(10, 10));

    //Put the editor pane and the text pane in a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
    paneScrollPane,
    paneScrollPane1);
    splitPane.setOneTouchExpandable(true);
    splitPane.setResizeWeight(0.5);
    JPanel leftPane = new JPanel(new GridLayout());
    leftPane.add(splitPane);
    leftPane.setBorder(BorderFactory.createCompoundBor der(
    BorderFactory.createTitledBorder(""),
    BorderFactory.createEmptyBorder(5,5,5,5)));

    add(leftPane, BorderLayout.WEST);

    //add textarea

    JTextArea linkcontent = new JTextArea(50,31);
    JScrollPane linkcontentscroll = new JScrollPane(linkcontent, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,Scro llPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    linkcontentscroll.setPreferredSize(new Dimension(400,750));
    linkcontentscroll.setMinimumSize(new Dimension(10, 10));
    JPanel rightpane= new JPanel();
    rightpane.add(linkcontent);
    add(rightpane, BorderLayout.EAST);

    //add buttons

    JButton[] buttons = new JButton[4];
    buttons[0] = new JButton("Uploading Lecture Notes");
    buttons[1] = new JButton("Automatic Link Discovery");
    buttons[2] = new JButton("Question Answering");
    buttons[3] = new JButton("Reviewing Suggested Links ");
    buttons[0].setMnemonic(KeyEvent.VK_U);
    buttons[1].setMnemonic(KeyEvent.VK_A);
    buttons[2].setMnemonic(KeyEvent.VK_Q);
    buttons[3].setMnemonic(KeyEvent.VK_R);
    JPanel uppane = new JPanel();
    for (int i=0; i<=3; i++){
    uppane.add(buttons[i]);
    }
    add(uppane, BorderLayout.NORTH);
    UpLoadListener listener= new UpLoadListener();
    buttons[0].addActionListener(listener);

    }


    private JTextPane createTextPane() {
    String[] initString =
    { ""
    };

    String[] initStyles =
    { "regular", "italic", "bold", "small", "large",
    "regular", "button", "regular", "icon",
    "regular"
    };

    JTextPane textPane = new JTextPane();
    StyledDocument doc = textPane.getStyledDocument();

    try {
    for (int i=0; i < initString.length; i++) {
    doc.insertString(doc.getLength(), initString[i],
    doc.getStyle(initStyles[i]));
    }
    } catch (BadLocationException ble) {
    System.err.println("Couldn't insert initial text into text pane.");
    }

    return textPane;
    }
    }

    /*
    * Copyright (c) 1995 - 2008 Sun Microsystems, Inc. All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * - Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * - Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * - Neither the name of Sun Microsystems nor the names of its
    * contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */

    package LiveLectureNotes;

    import java.io.*;
    import java.util.Vector;
    import java.awt.event.*;
    import javax.swing.*;


    public class UpLoadListener extends JPanel implements ActionListener {

    [B]LecturerArea note = new LecturerArea("Live Lecture Notes");[/B]
    private static final long serialVersionUID = 1L;
    Vector<String> data = new Vector<String>(50, 10);
    JFileChooser fc;
    BufferedReader mybuffer= null;
    int i=0;


    public UpLoadListener() {
    //Create a file chooser
    fc = new JFileChooser();

    }

    public void actionPerformed(ActionEvent e) {

    //Handle open button action.
    if (e.getActionCommand().equals("Uploading Lecture Notes")) {
    int returnVal = fc.showOpenDialog(UpLoadListener.this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    FileReader myhtml = null;
    try {
    myhtml = new FileReader(file.getPath());


    } catch (FileNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    mybuffer = new BufferedReader(myhtml);

    try {
    while(mybuffer.readLine() != null){
    data.add(mybuffer.readLine());
    System.out.println(data.elementAt(i));
    i++;
    }
    }

    catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();}
    }

    }
    }


    public static void main(String[] args) {

    //creating and showing this application's GUI.
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    //Turn off metal's use of bold fonts
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    }
    });
    }
    }

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

    The java stack trace should give you more precise info on the line where the Exception is thrown (I assume the main method you posted is abbreviated somehow because as posted it doesn't do anything). A rough scan of the code and I don't see anything in particular that jumps out. I'll re-assert that if you are reading a large file you may need to increase the maximum heap size with -Xmx (see previous post).

  5. #5
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

    there are some other classes in this package that I haven't sent them for you. when I execute the program without that mentioned line, it works properly and reads my file and writes it on the console, but when I want to create an object from LecturerArea class, IT SHOWS THE ERROR.

  6. #6
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

    sorry for bothering. I think the problem is that I instanciate a LecturereArea object in UploadListener class and agian I instanciatean UpLoadListenr object in LecturerArea class, and it causes an infinite loop? is that the point? what should I do if I need to do so?

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

    Quote Originally Posted by nasi View Post
    sorry for bothering. I think the problem is that I instanciate a LecturereArea object in UploadListener class and agian I instanciatean UpLoadListenr object in LecturerArea class, and it causes an infinite loop? is that the point? what should I do if I need to do so?
    Yup, that seems like it may be the issue. You can pass a reference of UpLoadListener to your LectureArea and directly add the listeners that way....or somehow manage your ActionListener a bit differently

  8. The Following User Says Thank You to copeg For This Useful Post:

    nasi (March 25th, 2010)

Similar Threads

  1. Replies: 15
    Last Post: February 28th, 2010, 10:30 PM
  2. Java heap space error
    By Loki in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 27th, 2010, 10:47 PM
  3. Out of memory - Java heap space
    By fraxx in forum Java Theory & Questions
    Replies: 4
    Last Post: November 24th, 2009, 05:26 AM
  4. OutOfMemoryError (Java heap space)
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2009, 11:56 AM
  5. Getting "AWT-EventQueue-0" java.lang.NullPointerException error
    By tryingtoJava in forum AWT / Java Swing
    Replies: 9
    Last Post: September 21st, 2009, 10:46 PM

Tags for this Thread