This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Java Messages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java Messages" Watch "Java Messages" New topic
Author

Java Messages

jonas okwara
Ranch Hand

Joined: Jun 22, 2004
Posts: 58
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

Joined: Oct 29, 2001
Posts: 8834
    
    7

Sounds like you have a null pointer at line 33. If you need more help, feel free to show us the relevant code.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
jonas okwara
Ranch Hand

Joined: Jun 22, 2004
Posts: 58
//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

Joined: Jun 22, 2004
Posts: 58
Still waiting for the reply
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8834
    
    7

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

Joined: Jun 22, 2004
Posts: 58
Thanks a lot joe ess

[Removed unessecary insult - please watch this in the future ]
[ July 01, 2004: Message edited by: Gregg Bolinger ]
 
Don't get me started about those stupid light bulbs.
 
subject: Java Messages
 
Similar Threads
Message exchange between session bean instances, is it possible?
validation: two forms on same page
IO System.out & System.err
Struts2 interceptors. glassfish VS Tomcat
Project Team members required for Open Source projects - Worldwide