かなり単純です。メイン プロジェクトにBIGclass
があり、「扱いにくく」なりました。own class
だから今日、私は自分の を作ってみることにcode
しましたclass
。これは私の「小さな」class
ですData storage
。このTRY/CATCH
ステートメントfloating
は、BIG クラスで単独で機能します。ただし、小さなクラスでは、NPE がスローされます。を作成するときに、Try/Catch システムが機能していないようown class
です。理由について何か考えはありますか?
file_in = openFileInput("array_saved");
Logcat によって呼び出されます。
...そしてこれはクラスです:
package com.eai.thepicker;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import android.app.Activity;
public class DataHandler extends Activity {
FileOutputStream file_out;
FileInputStream file_in;
ObjectOutputStream obj_out;
ObjectInputStream obj_in;
ArrayList<String> retrieved_data;
public DataHandler(){
}
@SuppressWarnings("unchecked")
public ArrayList<String> retrieveData(){
try {
file_in = openFileInput("array_saved");
obj_in = new ObjectInputStream(obj_in);
if(obj_in.available() > 0){
retrieved_data = (ArrayList<String>) obj_in.readObject();
}
else{
retrieved_data = new ArrayList<String>();
}
obj_in.close();
file_in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return retrieved_data;
}
public void saveData(ArrayList<String> data_out){
try {
file_out = openFileOutput("array_saved", 0);
obj_out = new ObjectOutputStream(file_out);
obj_out.writeObject(data_out);
obj_out.close();
file_out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}