这是我的代码:
不包括 Getter、Setter 和导入
零件类:
public class Part{
private String name;
private String id;
private int quantity;
private BigDecimal purchaseprice;
private BigDecimal saleprice;
private ArrayList<String> subparts;
private String description;
public Part(String File, String ID)
{
Part TempP = DataAccess.getPart(File, ID);
this.name = TempP.name;
this.id = TempP.id;
this.quantity = TempP.quantity;
this.purchaseprice = TempP.purchaseprice;
this.saleprice = TempP.saleprice;
this.subparts = TempP.subparts;
this.description = TempP.description;
}
public Part(){}
public Part(String name, String id, int quantity, BigDecimal purchaseprice,
BigDecimal saleprice, ArrayList<String> subparts, String description) {
this.name = name;
this.id = id;
this.quantity = quantity;
this.purchaseprice = purchaseprice;
this.saleprice = saleprice;
this.subparts = subparts;
this.description = description;
}
数据访问类:
public class DataAccess
{
public static ArrayList<Part> getAllParts(String aFile){
ArrayList<Part> PartList = new ArrayList<Part>();
try{
BufferedReader fin = new BufferedReader(new FileReader(aFile));
while(true){
String TempS[];
TempS = fin.readLine().split(",");
if(TempS[0] == null){break;}
ArrayList<String> subparts = new ArrayList<String>();
for(int i = 6; i < TempS.length; i++){
subparts.add(TempS[i]);
}
PartList.add(new Part(TempS[1], TempS[0],Integer.valueOf(TempS[2]),BigDecimal.valueOf(Double.valueOf(TempS[3])),BigDecimal.valueOf(Double.valueOf(TempS[4])),subparts,TempS[5]));
}
fin.close();
return PartList;
}catch(FileNotFoundException ex)
{
return PartList;
} catch (IOException e) {
e.printStackTrace();
}
return PartList;
}
所以问题是它按计划完美执行,直到它命中PartList.add(new Part(TempS[1], TempS[0],Integer.valueOf(TempS[2]),BigDecimal.valueOf(Double.valueOf(TempS[3])),BigDecimal.valueOf(Double.valueOf(TempS[4])),subparts,TempS[5]));
然后它抛出一个ClassNotFoundException
,我已经通过eclipse调试器完全跟踪它并且所有数据都是正确的......有人可以告诉我我做错了什么吗?以及对我的代码的任何其他建议也将不胜感激......
Exception in thread "main" java.lang.NullPointerException
at DataAccess.getAllParts(DataAccess.java:42)
at MainController.SummonParts(MainController.java:38)
at MainController.main(MainController.java:11)
调试器在崩溃之前读取第 48 行的 ClassNotFound 错误...