Exception In thread
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:
publicclass MainEngineeringToolFrameextends JFrameimplements 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...
publicstaticvoid 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:
publicclass DrawingPanelextends JPanelimplements 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
[3583 byte] By [
metana] at [2007-10-2 15:04:06]

You may want to compile your code using javac in command line and run using "java" (i.e., try running outside of IDE you mentioned). This is just to remove possible effects of IDE itself.
It just doesnt work man. Comand prompt stuckedwhile tryn to compile.. I waited several minutes, tried several times. even crtl+break doesnt work to stop it. Any more suggestions?i ve been workin about 2 days through this exception. geez :(
metana at 2007-7-13 13:52:46 >

You may want to post compilable code atleast. There is just too little info for any sort of help.
Since "***Main function loaded." is all that is displayed, the problem must start in the creation of the MainEngineeringToolFrame. Since "**super passed" is not displayed, the constructor must never complete. I would bet money that the call to super is not the problem.
So, the problem seems to be in the initialization of the variables of the MainEngineeringToolFrame. I would look at variables that use an initialization statement. For example, DrawingPanel dpanel = new DrawingPanel();
Since DrawingPanel creates an instance of MainEngineeringToolFrame, if MainEngineeringToolFrame tries to create an instance of DrawingPanel, you would have a loop which continues until memory runs out.
Hi;
thanx for reply.
Your observation is definetly correct. But I didnt understand your last paragraph.
Since DrawingPanel creates an instance of MainEngineeringToolFrame, if MainEngineeringToolFrame tries to create an instance of DrawingPanel, you would have a loop which continues until memory runs out.
do I have to create a loop checking the memory u mean?
cuz I dont have any kind of loop in my whole classes.
is it that necessary and useful?
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.
metana at 2007-7-13 13:52:46 >

> do I have to create a loop checking the memory u
> mean?
> cuz I dont have any kind of loop in my whole
> classes.
> is it that necessary and useful?
>
No, I mean you have created a loop. Think about what happens when your call "new MainEngineeringToolFrame()" Each time you call it, "new DrawingPanel() called. Each time you call "new DrawingPanel() a "new MainEngineeringToolFrame()" is called.
Shouldn't an instance of DrawingPanel use the MainEngineeringToolFrame object that created it? I think I would change the DrawingPanel constructor so it takes a MainEngineeriingToolFrame as an argument. Then assign the variable obj to the passed-in argment.
Ok my implementation is:
public class DrawingPanel extends Panel implements......
{
public MainEngineeringToolFrame obj;
public DrawingPanel (MainEngineeringToolFrame obj_)
{
super();
obj = obj_;
//some code.
}
}
other class
class MainEngineeringToolFrame extends JFrame implements......
{
public DrawingPanel mDrawingPnl = new DrawingPanel(new MainEngineeringToolFrame());
//constructor, main, some code
public Component buildPanel()
{
//some code
PanelBuilder panel = new PanelBuilder(layout);
//a lot of builder.add(....
builder.add(mDrawingPnl, cc.xy(5,1)); //null pointer ex
return builder.getPanel();
}
}
it now gives a null pointer exception to the builder.add(mDrawingPnl, cc.xy(5,1));
line in the MainEngineeringToolFrame class. Cristake.. Please help. :(
thanx on your helps
regards
metan.
metana at 2007-7-13 13:52:46 >

Never mind my last post. I ve fixed it.program is running perfectly.Thanx on your suggestions, and helps.argument to the constructor worked well. thank you.best regards.metan
metana at 2007-7-13 13:52:46 >
