我一直在开发一个用于娱乐用途的程序,我已经完成了布局,只需要完成估算某些值的进度。但是,每当我尝试输出或调用我的数组时,我都会不断收到空指针异常。这段代码是最新的,我尝试了几种不同的方法,但都没有奏效。我迫切需要帮助。
代码到我的主要。
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.beans.*;
public class DazzleMain
{
public static final int CLASSSIZE1 = 1;//subject to change
private static PlayerInput[] robbieArray = new PlayerInput [CLASSSIZE1];
public static LaunchWindows lws = new LaunchWindows();
// public static LoadWindow lw1 = new LoadWindow();
// public static PlayerShow ps = new PlayerShow ();
// public static NewWindow nw = NewWindow ();
// public static LoadCompWindow pcw = LoadCompWindow();
//PlayerInput player = new PlayerInput();
public static void main(String[] args) throws IOException, FileNotFoundException
{
System.out.println(CLASSSIZE1);
Scanner inputRobbieChamps = new Scanner (new FileReader("robbie_mccarthy_champs.txt"));
for (int x = 0; x>CLASSSIZE1; x++)
{
robbieArray[x].setChampName(inputRobbieChamps.next());
robbieArray[x].setRole(inputRobbieChamps.next());
robbieArray[x].setTier(inputRobbieChamps.nextInt());
}
//inputRobbieChamps.close();
// for (int x = 0;x>CLASSSIZE1; x++)
//{
System.out.println("The champ name is " + robbieArray[0].getChampName()); //+ "with a role of " + robbieArray[0].getRole() + " and a tier value of " + robbieArray[0].getTier());
// }
}
public static PlayerInput[] getArray()
{
return robbieArray;
}
}
我的日期文件(robbie_mccarthy_champs.txt):
test best 2
bear chair 3
我的窗口:
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.beans.*;
public class LaunchWindows extends JFrame
{
public JFrame launchFrame;
public LaunchWindows ()
{
frame();
}
public void main(String[] args)
{
}
private void frame()
{
launchFrame = new JFrame();
// launchFrame.setSize(900,300);
launchFrame.setVisible(true);
launchFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
launchFrame.setLayout(new GridLayout(2,4));
getLaunchFrame().setBounds(100, 300, 900, 300);
JLabel blankL1 = new JLabel(" ", SwingConstants.CENTER);
JLabel blankL2 = new JLabel(" ", SwingConstants.CENTER);
JLabel titleDL = new JLabel("Dazzle ", SwingConstants.RIGHT);
titleDL.setFont(new Font ("Casteliar", Font.PLAIN, 36));
JLabel titleSL = new JLabel (" Squad", SwingConstants.LEFT);
titleSL.setFont(new Font ("Casteliar", Font.PLAIN, 36));
JButton exitB = new JButton("Exit");
exitB.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{
System.exit(0);
}
});
JButton loadCompB = new JButton("Load Compositions");
JButton newB = new JButton("New Team Composition Entry");
newB.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{
//getLaunchFrame().setVisible(false);
}
});
JButton loadB = new JButton("Load Player Champions");
loadB.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{
// launchFrame.setVisible(false);
//DazzleMain.lw1.getLoadFrame().setVisible(true);
}
});
launchFrame.getContentPane().add(blankL1);
launchFrame.getContentPane().add(titleDL);
launchFrame.getContentPane().add(titleSL);
launchFrame.getContentPane().add(blankL2);
launchFrame.getContentPane().add(newB);
launchFrame.getContentPane().add(loadCompB);
launchFrame.getContentPane().add(loadB);
launchFrame.getContentPane().add(exitB);
launchFrame.setTitle("DAZZLERZ");
}
/*********************************************************/
public JFrame getLaunchFrame() {
return launchFrame;
}
public void setLaunchFrame(JFrame launchFrame) {
this.launchFrame = launchFrame;
}
}
玩家输入:
public class PlayerInput
{
/*******************************************/
//vars
// private String realName;
private String champName;
private String role;
private int tier;
/******************************************/
//methods
public PlayerInput ()
{
// realName = " ";
champName = " ";
role = " ";
tier = 0;
}
public PlayerInput (String cN, String r, int t)
{
// realName = rN;
champName = cN;
role = r;
tier = t;
}
/* public void setRealName(String rN)
{
realName = rN;
}*/
public void setChampName (String cN)
{
champName = cN;
}
public void setRole (String r)
{
role = r;
}
public void setTier (int t)
{
tier = t;
}
/* public String getRealName ()
{
return realName;
} */
public String getChampName ()
{
return champName;
}
public String getRole ()
{
return role;
}
public int getTier ()
{
return tier;
}
}