Forums Register Login

Java Messages

+Pie Number of slices to send: Send
My program compiles fine but spews out these error messages below.When I run it. I have been trying to figure out the problems without success. Please I will appreciate any help

Thx
jonas





Exception in thread "main" java.lang.NullPointerException
at QuestionBox.<init>(QuestionBox.java:33)
at QuestionBox.main(QuestionBox.java:100)
+Pie Number of slices to send: Send
Sounds like you have a null pointer at line 33. If you need more help, feel free to show us the relevant code.
+Pie Number of slices to send: Send
//Here is the code:

import java.text.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;


//The beginning of second frame
//--------------------------------

class QuestionBox extends JFrame implements ActionListener, DocumentListener {

private String candidateName;
private int fileNumber = 0;
private String[] myFiles = { "file1.txt", "file2.txt", "file3.txt", "file4.txt", "file5.txt"};
JPanel candidatePanel,textPanel,buttonPanel;
JLabel candidateLabel;
JTextField candidateTextField;
JButton startButton, cancelButton;

Font font = new Font ("New Courier", Font.PLAIN, 17);
//RealT real;
QuestionBox(){
super("Second Frame");

// Set up CandidateLabel
//-----------------------------------
candidateLabel = new JLabel();
candidateLabel.setFont( font );
candidateLabel.setText("Candidate_Name");
candidatePanel.add( candidateLabel);

//set up candidateTextField
//-------------------------------
candidateTextField = new JTextField( 25 );
candidateTextField.setPreferredSize(new Dimension(750, 45));
candidateTextField.setFont(font);
candidateTextField.getDocument().addDocumentListener(this);
candidateTextField.setHorizontalAlignment(JTextField.CENTER);
textPanel.add(candidateTextField);

// set up startButton
//------------------------
startButton = new JButton();
startButton.setPreferredSize(new Dimension(180, 40));
startButton.setBorder( new BevelBorder(BevelBorder.RAISED));
startButton.setFont( font);
startButton.setText("Begin_Exam");
startButton.setEnabled( true);
buttonPanel.add( startButton);
startButton.addActionListener( this );

//set up cancelButton
//----------------------------
cancelButton = new JButton();
cancelButton.setPreferredSize(new Dimension(180, 40));
cancelButton.setBorder( new BevelBorder(BevelBorder.RAISED));
cancelButton.setFont( font);
cancelButton.setText( "Cancel" );
buttonPanel.add(cancelButton);
cancelButton.addActionListener( this );

Container contentPane = getContentPane();
buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout( FlowLayout.CENTER));
textPanel.setLayout(new FlowLayout( FlowLayout.CENTER));
contentPane.add(buttonPanel, BorderLayout.SOUTH);
contentPane.add(candidatePanel, BorderLayout.CENTER);
contentPane.add(textPanel, BorderLayout.NORTH);
contentPane.setBackground(Color.RED);
setBounds(10, 10, 600, 300);
setResizable(false);
setVisible(true);
}

public void insertUpdate(DocumentEvent evt){
if ( evt.getDocument() == candidateTextField.getDocument()){
//startButton.setEnabled(true);
//candidateName == candidateTextField.getDocument();
}
}
public void removeUpdate(DocumentEvent evt){}
public void changedUpdate( DocumentEvent evt ){}
public void actionPerformed( ActionEvent evt ){
String actCmd = evt.getActionCommand();

//Start The test
//-----------------------------------------------
if ( actCmd.equals ("Begin_Exam")){
//real.makeVisible();
}
if (actCmd.equals("Cancel")){

}
}

public static void main( String args[]){
new QuestionBox();

}
}
+Pie Number of slices to send: Send
Still waiting for the reply
+Pie Number of slices to send: Send
 

Originally posted by jonas okwara:
Still waiting for the reply



Ya see, we're all volunteers here, answering these questions in our free time, so you may experience some delays.
Now, as for your problem, ya got two variables on line 33, candidatePanel and candidateLabel. You are getting a null pointer exception, which means that something on line 33 is null. So ask yerself: "where do I initalize those two variables".
[ July 01, 2004: Message edited by: Joe Ess ]
+Pie Number of slices to send: Send
Thanks a lot joe ess

[Removed unessecary insult - please watch this in the future ]
[ July 01, 2004: Message edited by: Gregg Bolinger ]
Everybody! Do the Funky Monkey! Like this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1202 times.
Similar Threads
Struts2 interceptors. glassfish VS Tomcat
Project Team members required for Open Source projects - Worldwide
validation: two forms on same page
IO System.out & System.err
Message exchange between session bean instances, is it possible?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:33:16.