0

I want to add two JPanels in a JFrame, I tryied this:

JPanel container;
JPanel jp;
JPanel jp2;
FlowLayout layout = new FlowLayout(FlowLayout.CENTER);
container.setLayout(layout);
jp = new Drawing();
jp2= new Drawing2();
container.add(jp);
container.add(jp2);
setContentPane(container)
setVisible(true);

container.setLayout gives me

java.lang.NullPointerException

Can you help me please? Thanks you.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
flofreelance
  • 944
  • 3
  • 14
  • 31
  • 1) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). 2) Always copy/paste error and exception output! 3) See [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) & [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/q/218384/418556) – Andrew Thompson Jan 22 '15 at 22:45
  • you do not have to manually setContentPane for a jPanel – JBALI Jan 22 '15 at 22:49
  • In every tutorial they use directly `new FlowLayout()` or `new FlowLayout(FlowLayout.CENTER)` and they haven't this exception. I try with `new FlowLayout(0)` and still have the exception... – flofreelance Jan 22 '15 at 22:55
  • You never instantiated `container`. Also, why not just set the FlowLayout as the layout manager of the existing content pane of the frame, instead of creating a new one? – David Conrad Jan 22 '15 at 23:04

0 Answers0