这是方法
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)。在 A 中导入类 PunchActivities 调用方法为
PunchActivities pa = new PunchActivities();
String result = pa.testFile(all the required parameters);
在运行时程序到达
FileInputStream fis = openFileInput(filename); in PunchActivities
但随后它返回到 A 类并出现 NullPointer 错误。为什么?????有人知道安卓的规则吗??