1,105,556 Community Members

Exception ERROR

Member Avatar
shibu2all
Light Poster
28 posts since Sep 2010
Reputation Points: -1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Can anyone please help me out in removing this error

Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1045)
at java.awt.Container.add(Container.java:365)
at Client.<init>(Client.java:33)
at Client.main(Client.java:17)

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class Client {
JFrame frame1;
JList list;
JList list1;
JTextField tf;
JButton send;
JButton lout;
JLabel label;
JScrollPane scrollpane;
JScrollPane scrollpane1;
public static void main(String args[]) {
       Client myclient = new Client();
		
		}
public Client()
{
		frame1 = new JFrame("Client");
		tf=new JTextField();
		send=new JButton("Send");
		lout=new JButton("Logout");
		label=new JLabel("Message");
		JPanel panel = new JPanel(); 
		panel.add(label);
        panel.add(tf);
        panel.add(label);
		panel.add(send);
		panel.add(lout);
		panel.add(scrollpane1);	
		panel.add(scrollpane);
		label.setBounds(10,320,80,30);
		tf.setBounds(10,350,220,50);
		send.setBounds(260,350,90,20);
		lout.setBounds(260,375,90,20);
		scrollpane.setBounds(10,20,220,300);
		scrollpane1.setBounds(250,20,120,300);
		
        frame1.add(panel);
		panel.setLayout(null);            	
        frame1.setSize(400,450);
	    frame1.setVisible(true);
		frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	

}
Member Avatar
mKorbel
Nearly a Posting Virtuoso
1,346 posts since Feb 2011
Reputation Points: 274 [?]
Q&As Helped to Solve: 277 [?]
Skill Endorsements: 14 [?]
 
0
 

1) place this code line panel.setLayout(null); before placing JComponent

2) variables JScrollPane scrollpane; and JScrollPane scrollpane1; aren't initialized and rest of JComponents

Member Avatar
shibu2all
Light Poster
28 posts since Sep 2010
Reputation Points: -1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks :-)

Question Answered as of 2 Years Ago by mKorbel
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: