Я пытаюсь прочитать txt-файл с содержимым json-формата в нем, я использую async-задачу, чтобы прочитать файл из папки с ресурсами, но получаю исключение nullpointer..below is my код.NullpointerException при чтении текстового файла из папки assests
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
Не знаю, где я делаю неправильно.
пожалуйста, напишите ваш LogCat ошибка – dipali
@dipali привет обновляется журнал – teekib
что 'DownloadJSON.java строка 75'? –