很抱歉,如果这有一个简单的解决方案,但我无法理解。
我遇到NumberFormatException(错误)问题:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: null
我有按钮,当它被按下时,它会有不同的东西,但它不喜欢代码中的一行。
行:if(Integer.parseInt(CarsLv1.cars[j]) == 0){
我试图让这一行与众不同,但它仍然会出现同样的错误:
if(j == 3){
Carslv1.cars = String Array。 所有其他像CarMain = Integer Arrays。
完整代码,如果点击了按钮:
if(ae.getSource() == jbtnBuildCarLv1){
if(CarMain.main[5] >=1){
if(CarMain.main[7] >0){
if(CarFrame.frames[1] >0){
for(int i=1;i <= 25;i+=2){
if(Part.parts[i] >0){
count0+=1;
}
else{
JOptionPane.showMessageDialog (null, "You don't have enought parts!", "No Parts", JOptionPane.ERROR_MESSAGE, ImagesHolder.NoPartsIcon);}
}
if (count0 == 13){
for (int j = 3;j <= 80; j+= 4){
if(Integer.parseInt(CarsLv1.cars[j]) == 0){
for(int i=1;i <= 25;i+=2){
Part.parts[i] --;
int count = Integer.parseInt(CarsLv1.cars[j]); count+=1;
CarsLv1.cars[j] = Integer.toString(count);
if(j == 3){
JOptionPane.showMessageDialog (null, "You have gained Aston Martin DB9!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Aston_Martin_DB9Icon);
}
if(j == 7){
JOptionPane.showMessageDialog (null, "You have gained Acura NSX!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Acura_NSXIcon);
}
if(j == 11){
JOptionPane.showMessageDialog (null, "You have gained Ford Mustang!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Ford_MustangIcon);
}
if(j == 15){
JOptionPane.showMessageDialog (null, "You have gained Moskvich 412!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Moskvich_412Icon);
}
if(j == 19){
JOptionPane.showMessageDialog (null, "You have gained Kia Venga!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Kia_VengaIcon);
}
if(j == 23){
JOptionPane.showMessageDialog (null, "You have gained Fiat 1500!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Fiat_1500Icon);
}
if(j == 27){
JOptionPane.showMessageDialog (null, "You have gained Ferrari Enzo!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Ferrari_EnzoIcon);
}
if(j == 31){
JOptionPane.showMessageDialog (null, "You have gained Aston Martin Rapide!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Aston_Martin_RapideIcon);
}
if(j == 35){
JOptionPane.showMessageDialog (null, "You have gained Koenigsegg CCX!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Koenigsegg_CCXIcon);
}
if(j == 39){
JOptionPane.showMessageDialog (null, "You have gained Honda Civic!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Honda_CivicIcon);
}
if(j == 43){
JOptionPane.showMessageDialog (null, "You have gained Cadilliac ATS!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Cadilliac_ATSIcon);
}
if(j == 47){
JOptionPane.showMessageDialog (null, "You have gained Mitsubishi Lancer Evolution X!", "Congralations", JOptionPane.INFORMATION_MESSAGE,ImagesHolder.Mitsubishi_LancerEvolutionXIcon);
}
if(j == 51){
JOptionPane.showMessageDialog (null, "You have gained Infiniti FX!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Infiniti_FXIcon);
}
if(j == 55){
JOptionPane.showMessageDialog (null, "You have gained Lancia Thema!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Lancia_ThemaIcon);
}
if(j == 59){
JOptionPane.showMessageDialog (null, "You have gained Volvo XC90!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Volvo_XC90Icon);
}
if(j == 63){
JOptionPane.showMessageDialog (null, "You have gained Acura CSX!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Acura_CSXIcon);
}
if(j == 67){
JOptionPane.showMessageDialog (null, "You have gained Saab Sonett II!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Saab_SonettIIIcon);
}
if(j == 71){
JOptionPane.showMessageDialog (null, "You have gained Renault Floride!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Renault_FlorideIcon);
}
if(j == 75){
JOptionPane.showMessageDialog (null, "You have gained BMW e34!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.BMW_e34Icon);
}
if(j == 79){
JOptionPane.showMessageDialog (null, "You have gained Chrysler Cordoba!", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.Chrysler_CordobaIcon);
}
else{
JOptionPane.showMessageDialog(null, "You have colected all 1 LVL cars", "Congralations", JOptionPane.INFORMATION_MESSAGE, ImagesHolder.MaxUpgradeIcon);
}
}
}
}
}
}
else{
JOptionPane.showMessageDialog (null, "You don't have 1 LVL car frame!", "No Car Frame", JOptionPane.ERROR_MESSAGE, ImagesHolder.NoFrameIcon);}
}
else{
JOptionPane.showMessageDialog (null, "You don't have available garage slot!", "No Garage Slot", JOptionPane.ERROR_MESSAGE, ImagesHolder.NoGarageIcon);
}
}
else{
JOptionPane.showMessageDialog (null, "You don't have enought player level!", "No Player Level", JOptionPane.ERROR_MESSAGE, ImagesHolder.NoPlayerIcon);
}
}
CarsLv1Class(Array)代码:
package Clicker;
public class CarLevel1Holder {
public String cars[] = new String[80];
public CarLevel1Holder(){
}
public void CarsMaker(String a1,int k, String a2,int k1, String a3,int k2,String a4,int k3){
cars[k] = a1;
cars[k1] = a2;
cars[k2] = a3;
cars[k3] = a4;
}
public void MakeCars(){
int u = 0;int i = 1;int o = 2;int p = 3;
CarsMaker("Type", u,"Aston_Martin", i,"British",o, "0", p); //Aston_Martin_DB9
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Acura", i,"Japanese",o, "0",p); //Acura_NSX
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Ford", i,"American", o,"0",p); //Ford_Mustang
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Moskvich", i,"Russian", o,"0",p); //Moskvich_412
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Kia", i,"Korean",o,"0",p); //Kia_Venga
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Fiat", i,"Italian", o,"0",p); //Fiat_1500
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Ferrari", i,"Italian", o,"0",p); //Ferrari_Enzo
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Aston_Martin", i,"British", o,"0",p); //Aston_Martin_Rapide
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Koenigsegg", i,"Swedish", o,"0",p); //Koenigsegg_CCX
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Honda", i,"Japanese", o,"0",p); //Honda_Civic
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Cadilliac", i,"American", o,"0",p); //Cadilliac_ATS
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Mitsubishi", i,"Japanese", o,"0",p); //Mitsubishi_LancerEvolutionX
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Infiniti", i,"Japanese", o,"0",p); //Infiniti_FX
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Lancia", i,"Italian", o,"0",p); //Lancia_Thema
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Volvo", i,"Swedish", o,"0",p); //Volvo_XC90
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Acura", i,"Japanese", o,"0",p); //Acura_CSX
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Saab", i,"Swedish", o,"0",p); //Saab_SonettII
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Renault", i,"French", o,"0",p); //Renault_Floride
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"BMW", i,"Germany", o,"0",p); //BMW_e34
u += 4; i += 4; o +=4; p+= 4;
CarsMaker("Type", u,"Chrysler", i,"American", o,"0",p); //Chrysler_Cordoba
u += 4; i += 4; o +=4; p+=4;
// CarsLv1 Aston_Martin_DB9 = new CarsLv1("Type", "Aston_Martin", "British", 0);
// CarsLv1 Acura_NSX = new CarsLv1("Type", "Acura", "Japanese", 0);
// CarsLv1 Ford_Mustang = new CarsLv1("Type", "Ford", "American", 0);
// CarsLv1 Moskvich_412 = new CarsLv1("Type", "Moskvich", "Russian", 0);
// CarsLv1 Kia_Venga = new CarsLv1("Type", "Kia", "Korean", 0);
// CarsLv1 Fiat_1500 = new CarsLv1("Type", "Fiat", "Italian", 0);
// CarsLv1 Ferrari_Enzo = new CarsLv1("Type", "Ferrari", "Italian", 0);
// CarsLv1 Aston_Martin_Rapide = new CarsLv1("Type", "Aston_Martin", "British", 0);
// CarsLv1 Koenigsegg_CCX = new CarsLv1("Type", "Koenigsegg", "Swedish", 0);
// CarsLv1 Honda_Civic = new CarsLv1("Type", "Honda", "Japanese", 0);
// CarsLv1 Cadilliac_ATS = new CarsLv1("Type", "Cadilliac", "American", 0);
// CarsLv1 Mitsubishi_LancerEvolutionX = new CarsLv1("Type", "Mitsubishi", "Japanese", 0);
// CarsLv1 Infiniti_FX = new CarsLv1("Type", "Infiniti", "Japanese", 0);
// CarsLv1 Lancia_Thema = new CarsLv1("Type", "Lancia", "Italian", 0);
// CarsLv1 Volvo_XC90 = new CarsLv1("Type", "Volvo", "Swedish", 0);
// CarsLv1 Acura_CSX = new CarsLv1("Type", "Acura", "Japanese", 0);
// CarsLv1 Saab_SonettII = new CarsLv1("Type", "Saab", "Swedish", 0);
// CarsLv1 Renault_Floride = new CarsLv1("Type", "Renault", "French", 0);
// CarsLv1 BMW_e34 = new CarsLv1("Type", "BMW", "Germany", 0);
// CarsLv1 Chrysler_Cordoba = new CarsLv1("Type", "Chrysler", "American", 0);
}
}
答案 0 :(得分:0)
if(Integer.parseInt(CarsLv1.cars[j]) == 0){
你应该读这个
if(Integer.parseInt(null) == 0){
因为在这种情况下CarLv1.cars [j]为null。你需要解决这个问题。您可能希望使用调试器并逐步执行,以便捕获j
的确切值答案 1 :(得分:0)
抓住数字格式例外?
try{
int count = Integer.parseInt(CarsLv1.cars[j]);
if(count == 0){
for(int i=1;i <= 25;i+=2){
...
}
}
}catch(Exception e){}