Hi,
I have written a code for dragging and dropping a component from one panel to another in group layout, but when i drop in panel2 it throwing NullPointerException, can any one please tell me where i am wrong in below code.

Java Code:
public class sample extends JFrame  implements DragGestureListener, DragSourceListener,
DropTargetListener, Transferable{

	private static final long serialVersionUID = 1L;
	private JButton jButton1;
	private JPanel jPanel0;
	private JPanel jPanel1;
	private int X,Y;
	public sample() {
		initComponents();
	}
    
	private void initComponents() {
		setLayout(new GroupLayout());
		add(getJPanel0(), new Constraints(new Leading(2, 156, 10, 10), new Trailing(0, 225, 6, 6)));
		add(getJPanel1(), new Constraints(new Leading(176, 142, 10, 10), new Trailing(6, 219, 6, 6)));
DragDrop dndListener = new DragDrop();

	    DragSource dragSource = new DragSource();
 DropTarget dropTarget2 = new DropTarget(jPanel1, DnDConstants.ACTION_COPY, 
	                dndListener);
 DragGestureRecognizer dragRecognizer2 = dragSource.
	                createDefaultDragGestureRecognizer(jButton1, DnDConstants.ACTION_COPY, dndListener);
setSize(320, 240);
	}

	
static final DataFlavor[] supportedFlavors = {null};
    
    static {
        try {
            supportedFlavors[0] = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    Object object;
	private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
    // Transferable methods.
    
	public Object getTransferData(DataFlavor flavor) {
        if (flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)) {
            return object;
        } else {
            return null;
        }
    }

    public DataFlavor[] getTransferDataFlavors() {
        return supportedFlavors;
    }

    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType);
    }
    // DragGestureListener method.
    public void dragGestureRecognized(DragGestureEvent ev) {
        ev.startDrag(null, this, this);
    }
    
    // DragSourceListener methods.
    public void dragDropEnd(DragSourceDropEvent ev) {
    }

    public void dragEnter(DragSourceDragEvent ev) {
    }

    public void dragExit(DragSourceEvent ev) {
    	System.out.println("hiii");
    }

    public void dragOver(DragSourceDragEvent ev) {
        object = ev.getSource();
    }

    public void dropActionChanged(DragSourceDragEvent ev) {
    }
    // DropTargetListener methods.
    public void dragEnter(DropTargetDragEvent ev) {
    }

    public void dragExit(DropTargetEvent ev) {
    }

    public void dragOver(DropTargetDragEvent ev) {
        dropTargetDrag(ev);
    }

    public void dropActionChanged(DropTargetDragEvent ev) {
        dropTargetDrag(ev);
    }

    void dropTargetDrag(DropTargetDragEvent ev) {
        ev.acceptDrag(ev.getDropAction());
    }

    public void drop(DropTargetDropEvent ev) {
        ev.acceptDrop(ev.getDropAction());
        try {
            Object target = ev.getSource();
            
            Object source = ev.getTransferable().getTransferData(supportedFlavors[1]);
            
            Component component = ((DragSourceContext) source).getComponent();
            
            Container oldContainer = component.getParent();
            
            Container container = (Container) ((DropTarget) target).getComponent();
            oldContainer.validate();
            oldContainer.repaint();
            container.add(jButton1,new Constraints(new Leading(X,10,10), new Leading(Y,10,10)));
            
            container.validate();
            container.repaint();
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }
        ev.dropComplete(true);
    }
	
    private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setBackground(Color.lightGray);
			jPanel1.setLayout(new GroupLayout());
			pack();
		}
		return jPanel1;
	}