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
Chris Uppal - 16 Mar 2006 11:24 GMT
> 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
Mehmet Metan - 16 Mar 2006 12:58 GMT
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
Mehmet Metan - 16 Mar 2006 13:06 GMT
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.
Rhino - 16 Mar 2006 16:24 GMT
> hello to all.
>
[quoted text clipped - 66 lines]
> 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
[quoted text clipped - 3 lines]
> best regards
> metan
Rhino
Mehmet Metan - 16 Mar 2006 17:03 GMT
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.