ここに方法があります
public String testFile(int numofpunches, String filename, int picture, int cancelpix){
String string="";
Boolean a;
FILENAME = filename;
try {
FileInputStream fis = openFileInput(filename);
try{
int counter = fis.read( mIds, 0,numofpunches);
fis.close();
int i=0;
while( i <counter ){
if(mIds[i] == 'c'){
mThumbIds[i++] = picture; //R.drawable.crab;
string=string.concat("c");
}else{
mThumbIds[i] = cancelpix;
string=string.concat("x");
ImageView punchit = (ImageView)
findViewById(mypunches[i++]);
punchit.setImageResource(R.drawable.punchboxcancelled);
}
}
String testfordone = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
a= string.equals(testfordone.substring(0,numofpunches));
if(a){
return "done";
}
}catch (IOException e){
}
}catch (FileNotFoundException e) {
try {//initialize
String FILENAME = filename;
FileOutputStream fos = openFileOutput(FILENAME,
Context.MODE_PRIVATE);
string = "cccccccccccccccccccccccccccccccccccccc";
string.substring(0,numofpunches);
try {
fos.write(string.getBytes());
fos.close();
int counter = 0;
while(counter < numofpunches ){
mThumbIds[counter++] = picture;
}
}catch(IOException err){
}
}catch(FileNotFoundException error){
};
}
このメソッドが配置されている同じクラス (A) から呼び出します。次に、同じメソッドで新しいクラス (PunchActivities) を作成します。クラス PunchActivities を A にインポートし、メソッドを次のように呼び出します。
PunchActivities pa = new PunchActivities();
String result = pa.testFile(all the required parameters);
実行時に、プログラムは
FileInputStream fis = openFileInput(filename); in PunchActivities
しかし、NullPointer エラーでクラス A に戻ります。どうして?????アンドロイドのルールを知っている人はいますか??