Exception In thread "SyntheticImageGenerator" URGENT HELP

M

Mehmet Metan

hello to all.

Exception In thread "SyntheticImageGenerator"
java.lang.OutOfMemoryError: Java heap space


I ve two classes. and I am getting the above error.

Neccessary code is below:

public class MainEngineeringToolFrame extends JFrame implements
ActionListener.
{
//Some Code...
public MainEngineeringToolFrame
{
super("HELP PLS");
System.out.println("**super passed");
setBounds(120,300,1024,428);
setResizable(false);
System.out.println("**next code: Set Visible true");
setVisible(true);
}

//Some Code...

public static void main(String[] args)
{
System.out.println("***Main function loaded.");
MainEngineeringToolFrame frame = new MainEngineeringToolFrame();
System.out.println("***Object created.");
// frame.setTitle
// frame.setResizable
// getContentPane
// add(....
setVisible(true);
}

}



This is my fiirst class.
I created another class for the panel. where painting will occur in it.
necessary code is below:

public class DrawingPanel extends JPanel implements MouseListener,
MouseMotionListener
{
MainEngineeringToolFrame obj = new MainEngineeringToolFrame();

public DrawingPanel()
{
super();
addMouseListener(this);
addMouseMotionListener(this);
setLayout(null);
}

//paint func.
//implemented methods.
}




At the System Line it only prints:

***Main function loaded.


What means it can't create an object from itself in the main class.
than program tries to build itself some time.
And gives an error message like:
I thought increasing the heap space in ecliopse from VM arguments in
run properties window in arguments tag. where under Java Application
(Im thinking u r familliar with eclipse.)

Why does it happpen? I thought this kind of exception may occur in an
infiniteloop where infinite objects are created. Well I dont even have
a loop or Im not creating infinite number of objects..

Any helps appriciated
best regards
metan
 
C

Chris Uppal

Mehmet said:
public class MainEngineeringToolFrame extends JFrame implements
ActionListener.
{ [...]

public class DrawingPanel extends JPanel implements MouseListener,
MouseMotionListener
{
MainEngineeringToolFrame obj = new MainEngineeringToolFrame();

I doubt if you are showing us the code that we need to see.

One thing that ocurs to me, though, is that if your code adds a new
DrawingPanel to a MainEngineeringToolFrame then you'll have problems. Creating
the DrawingPanel will create a new MainEngineeringToolFrame, which will in turn
will create a new DrawingPanel, which will....

-- chris
 
M

Mehmet Metan

Ok thats right. I initialize the DrawingPanel in the
MainEngineeringToolFrame like:

private DrawingPanel mDrawingPnl = new DrawingPanel();

other operations for mDrawingPnl in the MainEngineeringToolFrame class
are like below:

public void initComponents() //called in constructor
{
// some code.
mDrawingPnl.setBounds(50,50,200,400);
mDrawingPnl.setVisible(true); // I dont know =]
}

public Component buildPanel() //function is for adding components to
the defined layout with coordinates.
//I ve used JGoodies forms for layout manage. dont need to focus on
that
{
//some code
PanelBuilder panel = new PanelBuilder(layout);
//a lot of builder.add(....
builder.add(mDrawingPnl, cc.xy(5,1)); //coordinates.

return builder.getPanel();
}

main
{
//some code
frame.add(frame.buildPanel());
frame.setVisible(true);
}

And I replaced the DrawingPanel class like this

public class DrawingPanel extends JPanel implements MouseListener,
MouseMotionListener
{
public MainEngineeringToolFrame obj = new
MainEngineeringToolFrame();

but now I m getting a lot of nullPointer exceptions refering to the
variables derived from obj.
Such as in paint function

public void paint(Graphics g)
{
super.paint(g);
g.setColor(obj.getMCurrentColor()); //used the getter method of Color
currentColor variable
}

4 exceptions occured in this line
g.setColor(obj.getMCurrentColor());

saying:
Exception in thread "AWT-EventQueue-0' java.lang.NullPointerException


4 exceptions occured right after each other in one time.


Your helps are appriciated. Thanx again.
and help again pls :)

best regards
metan
 
M

Mehmet Metan

I ve tried commenting that line but all other obj.smthing related code
is having a null pointer exceptiion. i ve initialized the obj object.
Why i am getting a null pointer exception? Two classes are in the same
package.

regards.
 
R

Rhino

Mehmet Metan said:
hello to all.

Exception In thread "SyntheticImageGenerator"
java.lang.OutOfMemoryError: Java heap space


I ve two classes. and I am getting the above error.

Neccessary code is below:

public class MainEngineeringToolFrame extends JFrame implements
ActionListener.
{
//Some Code...
public MainEngineeringToolFrame
{
super("HELP PLS");
System.out.println("**super passed");
setBounds(120,300,1024,428);
setResizable(false);
System.out.println("**next code: Set Visible true");
setVisible(true);
}

//Some Code...

public static void main(String[] args)
{
System.out.println("***Main function loaded.");
MainEngineeringToolFrame frame = new MainEngineeringToolFrame();
System.out.println("***Object created.");
// frame.setTitle
// frame.setResizable
// getContentPane
// add(....
setVisible(true);
}

}



This is my fiirst class.
I created another class for the panel. where painting will occur in it.
necessary code is below:

public class DrawingPanel extends JPanel implements MouseListener,
MouseMotionListener
{
MainEngineeringToolFrame obj = new MainEngineeringToolFrame();

public DrawingPanel()
{
super();
addMouseListener(this);
addMouseMotionListener(this);
setLayout(null);
}

//paint func.
//implemented methods.
}




At the System Line it only prints:

***Main function loaded.


What means it can't create an object from itself in the main class.
than program tries to build itself some time.
And gives an error message like:
I thought increasing the heap space in ecliopse from VM arguments in
run properties window in arguments tag. where under Java Application
(Im thinking u r familliar with eclipse.)
If you are using Eclipse, then you will probably get the best understanding
of the problem by running the debugger and stepping through the program one
line at a time. If you do this carefully, you will soon see where the
program starts to misbehave and you will probably be able to figure out why.
Maybe some object that you thought was created correctly wasn't created
after all and the problems all stem from that.

Try this approach and if you see some behaviour that you don't understand,
ask here and someone may be able to explain why the bad behaviour is taking
place.

Why does it happpen? I thought this kind of exception may occur in an
infiniteloop where infinite objects are created. Well I dont even have
a loop or Im not creating infinite number of objects..

Any helps appriciated
best regards
metan
Rhino
 
M

Mehmet Metan

well the problem is because of the MainEngineeringToolFrame obj = new
MainEngineeringToolFrame(); object after debugging. but i am still not
able to understand why..

well in this decleration it is expected that a null pointer exception
will occur

public MainEngineeringToolFrame obj;


but the program window is visible and by buttons and stuff are
available. However any action is taken it is giving a null pointer
exception to the

obj.something

declerations. Ok I understand that. It is normal
but when i initialize the object with its constructor like

public MainEngineeringToolFrame obj = new MainEngineeringToolFrame();


it is giving the

Exception In thread "SyntheticImageGenerator"
java.lang.OutOfMemoryError: Java heap space

error and terminates the program without initialization. What would i
have to do?

In addition I think the declarations and initializations of
DrawingPanel object in the MainEngineeringToolFrame is correct.. if not
may be the problem can be solved there..

necessary code is below:

public class MainEngineeringToolFrame extends JFrame implements
ActionListener.
{
//Some Code...
private DrawingPanel mDrawingPnl = new DrawingPanel();

public MainEngineeringToolFrame()
{
super("HELP PLS");
setBounds(120,300,1024,428);
setResizable(false);
initComponents();
setVisible(true);

}
public void initComponents() //called in constructor
{
// some code.
mDrawingPnl.setBounds(50,50,200,400);
mDrawingPnl.setVisible(true); // I dont know =]

}

//function is for adding components to the defined layout with
coordinates.
//I ve used JGoodies forms for layout manage. dont need to focus on
public Component buildPanel()
{
//some code
PanelBuilder panel = new PanelBuilder(layout);
//a lot of builder.add(....
builder.add(mDrawingPnl, cc.xy(5,1)); //coordinates.

return builder.getPanel();

}
//Some Code...

public static void main(String[] args)
{
System.out.println("***Main function loaded.");
MainEngineeringToolFrame frame = new MainEngineeringToolFrame();
System.out.println("***Object created.");
// frame.setTitle
// frame.setResizable
// getContentPane
// add(....
frame.add(frame.buildPanel());
setVisible(true);
}

}



Second class

public class DrawingPanel extends JPanel implements MouseListener,
MouseMotionListener
{
MainEngineeringToolFrame obj = new MainEngineeringToolFrame();

public DrawingPanel()
{
super();
addMouseListener(this);
addMouseMotionListener(this);
setLayout(null);
}

public void paint(Graphics g)
{
super.paint(g);
g.setColor(obj.getMCurrentColor()); //used the getter method of
Color currentColor variable
//Exception will occur.

}
//implemented methods.

}



Any suggestions are very appriciated.
Thanx
regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top