Original Post
I keep getting a null pointer exception and it just isn''t acting correctly Please someone help me fix it... thanks
/Source
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.io.*;
class Game {
public static final int standardNum = 10;
public String qAndA[]; // This array holds the question and the answer
public String points[];
public static int gameNum; // Keeps track of the total number of games
public int myNum; // particular number for this game
public int numAns; // the number of answers for this game
}
//4a1e62 purple
//A6870D gold
public class FeudGame extends JFrame
{
// array of games
public Game games[];
// interface
JTextField ansSlots[], question;
JPanel mainPanel, secPanel;
JButton reset;
/* This is the constructor of the main class, FeudGame
it will be passed the number of games */
//The interface is implemented here...
public FeudGame(int numGames)
{
games = new Game[numGames];
//games[0].qAndA = new String[Game.standardNum];
mainPanel = new JPanel();
secPanel = new JPanel();
question = new JTextField(20);
ansSlots = new JTextField[10];
getContentPane().add(mainPanel, BorderLayout.CENTER);
getContentPane().add(secPanel, BorderLayout.SOUTH);
reset = new JButton("RESET");
secPanel.add(question);
secPanel.add(reset);
}
/*Later on this function will be placed in a for loop so that we may manually enter
the data for each game*/
public static Game MakeGame(int numberOfAns, Game g) throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the question");
/*g.qAndA[0]*/ String ques = input.readLine();
System.out.println("3");
/*g.points[0]*/ g.qAndA[0] = g.points[0]= ques;
System.out.println(g.qAndA[0]);
for( int i = 1; i < numberOfAns; i++)
{
System.out.println("Enter the answer" + i + "to the question");
String answers = input.readLine();
g.qAndA = answers;
System.out.println("Enter the number of points");
String pts = input.readLine();
g.points[i] = pts;
}
g.myNum = ++Game.gameNum;
return g;
}
public static void main(String Args[])
{
FeudGame feud = new FeudGame(1);
System.out.println("4");
try {
feud.games[0] = FeudGame.MakeGame(2, new Game());
} catch(Exception e) {}
//System.out.println(feud.games[0].qAndA[0]);
// for(int i=0; i < 14; i++)
// feud.games[i] = FeudGame.MakeGame(Game.standardNum, feud.games[i]);
}
}
Source/