• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Messages

 
jonas okwara
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Joe Ess
Bartender
Posts: 9318
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you have a null pointer at line 33. If you need more help, feel free to show us the relevant code.
 
jonas okwara
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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();

}
}
 
jonas okwara
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still waiting for the reply
 
Joe Ess
Bartender
Posts: 9318
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
jonas okwara
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot joe ess

[Removed unessecary insult - please watch this in the future ]
[ July 01, 2004: Message edited by: Gregg Bolinger ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic