File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 8836
    
    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: 8836
    
    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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Messages
 
Similar Threads
Project Team members required for Open Source projects - Worldwide
Struts2 interceptors. glassfish VS Tomcat
IO System.out & System.err
Message exchange between session bean instances, is it possible?
validation: two forms on same page