jsonを解析しようとしましたが、問題があります。アプリを実行すると、次のエラーが発生します。ログを印刷しようとしましたが、印刷されません。彼は私のrss.jsonを読むことができませんか?または別の問題?
致命的な例外が発生しています:AsyncTask#1ログ猫でこのエラーが発生しましたAVD4.1.2でコードを実行できます
Logcat
FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:64)
at java.io.InputStreamReader.<init>(InputStreamReader.java:79)
at com.gazetaimage.MainActivity$backTask.doInBackground(MainActivity.java:112)
at com.gazetaimage.MainActivity$backTask.doInBackground(MainActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 5 more
AsyncTaskコード
class backTask extends AsyncTask<String, Void, JSONObject>{
InputStream ips;
String jstring = null;
JSONObject jsonObj = null;
MainActivity activity;
@Override
protected JSONObject doInBackground(String... params) {
try {
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://mysite.com/RSS/gazeta.js");
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
ips = entity.getContent();
Log.d("Log", ips.toString());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
//MainActivity.java:112 ERROR --->
BufferedReader bufff = new BufferedReader(new InputStreamReader(ips, "UTF-8"));
Log.d("Log", bufff.toString());
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = bufff.readLine()) != null){
sb.append(line + "\n");
}
ips.close();
jstring = sb.toString();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
jsonObj = new JSONObject(jstring);
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObj;
}
protected void onPostExecute(JSONObject result){
super.onPostExecute(result);
}
public void link(MainActivity mainActivity) {
activity = mainActivity;
}
public void unlink() {
activity = null;
}
}