私の質問は、ファイルからデータを読み取るクラスを作成していて、データは
農産物、3554、ブロッコリー、5.99、1
農産物、3554、ブロッコリー、5.99、1
農産物、3555、ニンジン、2.23、0.25
農産物、3555、ニンジン、2.23、0.25
農産物、3555、ニンジン、2.23、0.25
-------------------------------------------------- --// ファイル終了
Product[] p= new Product[num];
int k=0;
try
{
File f = new File("somefile.txt");
Scanner s= new Scanner(f);
while(s.hasNextLine())
{
String txt = s.nextLine();
String[] field = txt.split(",");
p[k] = new Product();//name,code,veg,price,unit are the variable and defined in theparent class named Product and toString method also
p[k].name=field[0];
p[k].code=field[1];
p[k].veg=field[2];
p[k].price=field[3];
p[k].unit=field[4];
k++;
}
今私はメソッドを作成したい
public static Product delete(int pos)
{
return p[pos] // this will represent the toString representation of particular inde
}
私はこのコードを試していますが、p[pos] が定義されていないという例外が発生します
このメソッドを取得する他の方法や方法はありますか?
物体