json 形式のコンテンツを含む txt ファイルを読み込もうとしています。非同期タスクを使用してアセット フォルダーからファイルを読み込んでいますが、nullpointer 例外が発生します。以下は私のコードです。
public class DownloadJSON extends AsyncTask<Void, Void, Void> {
private MyDBAdapter dbHelper;
String fileName = "json.txt";
Context c;
private static final String result = null;
ArrayList<HashMap<String, String>> arraylist;
@Override
protected Void doInBackground(Void... params) {
readFileFromAssets(fileName,c);
return null;
}
public static String readFileFromAssets(String fileName, Context c) {
AssetManager assetManager = c.getAssets();
InputStream is = null;
try {
is = assetManager.open(fileName);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String text = new String(buffer);
System.out.println("tex===========t"+ text);
return text;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
以下は私のログトレースです
09-24 10:53:25.430: E/AndroidRuntime(1714): Caused by: java.lang.NullPointerException
09-24 10:53:25.430: E/AndroidRuntime(1714): at com.markupartist.android.actionbar.example.DownloadJSON.readFileFromAssets(DownloadJSON.java:75)
09-24 10:53:25.430: E/AndroidRuntime(1714): at com.markupartist.android.actionbar.example.DownloadJSON.doInBackground(DownloadJSON.java:27)
09-24 10:53:25.430: E/AndroidRuntime(1714): at com.markupartist.android.actionbar.example.DownloadJSON.doInBackground(DownloadJSON.java:1)
09-24 10:53:25.430: E/AndroidRuntime(1714): at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-24 10:53:25.430: E/AndroidRuntime(1714): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-24 10:53:25.430: E/AndroidRuntime(1714): ... 5 more
どこが間違っているのかわかりません。