Nullが何を言っているのか正確に理解しようとしましたが、エラーがある行に正しい値の配列を入れました。だから誰かが私に解決策を与えることができれば素晴らしいだろう。onProgressUpdateのNullPointerException
LogCat:
02-29 23:03:52.078: D/Surface(4619): Surface is full screen
02-29 23:03:52.088: D/AndroidRuntime(4619): Shutting down VM
02-29 23:03:52.088: W/dalvikvm(4619): threadid=1: thread exiting with uncaught exception (group=0x4001d560)
02-29 23:03:52.088: E/AndroidRuntime(4619): FATAL EXCEPTION: main
02-29 23:03:52.088: E/AndroidRuntime(4619): java.lang.NullPointerException
02-29 23:03:52.088: E/AndroidRuntime(4619): at com.ratetheplate.application.Reviews$Read.onProgressUpdate(Reviews.java:115)
02-29 23:03:52.088: E/AndroidRuntime(4619): at com.ratetheplate.application.Reviews$Read.onProgressUpdate(Reviews.java:1)
02-29 23:03:52.088: E/AndroidRuntime(4619): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:432)
02-29 23:03:52.088: E/AndroidRuntime(4619): at android.os.Handler.dispatchMessage(Handler.java:99)
02-29 23:03:52.088: E/AndroidRuntime(4619): at android.os.Looper.loop(Looper.java:130)
02-29 23:03:52.088: E/AndroidRuntime(4619): at android.app.ActivityThread.main(ActivityThread.java:3835)
02-29 23:03:52.088: E/AndroidRuntime(4619): at java.lang.reflect.Method.invokeNative(Native Method)
02-29 23:03:52.088: E/AndroidRuntime(4619): at java.lang.reflect.Method.invoke(Method.java:507)
02-29 23:03:52.088: E/AndroidRuntime(4619): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:883)
02-29 23:03:52.088: E/AndroidRuntime(4619): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
02-29 23:03:52.088: E/AndroidRuntime(4619): at dalvik.system.NativeStart.main(Native Method)
のJava:
package com.ratetheplate.application;
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
public class Reviews extends Activity {
TextView rssStuff;
HttpClient client;
JSONObject json;
final static String URL = "http://api.tumblr.com/v2/blog/ratetheplate.tumblr.com/posts.json?api_key=*********************";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.reviews);
rssStuff = (TextView) findViewById(R.id.rss);
client = new DefaultHttpClient();
new Read().execute("posts");
}
public JSONObject lastPost(String review) throws ClientProtocolException,
IOException, JSONException {
HttpGet get = new HttpGet(URL.toString());
HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity e = r.getEntity();
String data = EntityUtils.toString(e);
JSONArray timeline = new JSONArray(data);
JSONObject last = timeline.getJSONObject(0);
return last;
} else {
Toast.makeText(Reviews.this, "Error", Toast.LENGTH_SHORT);
return null;
}
}
public class Read extends AsyncTask<String, Integer, String> {
String title, msg;
ProgressDialog dialog;
protected void onPreExectute() {
title = "Loading";
msg = "Loading Reviews...";
dialog = new ProgressDialog(Reviews.this);
dialog.setTitle(title);
dialog.setMessage(msg);
dialog.setIndeterminate(false);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setProgress(0);
dialog.setMax(100);
dialog.show();
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
for (int i = 0; i < 20; i++) {
publishProgress(5);
try {
Thread.sleep(88);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
dialog.dismiss();
try {
json = lastPost("posts");
return json.getString(params[0]);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onProgressUpdate(Integer... progress) {
dialog.incrementProgressBy(progress[0]);
setProgress(progress[0]);
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
rssStuff.setText(result);
}
}
}
レビュー.java、115行目を参照してください。 –
これはonProgressUpdateの最初の行です。 dialog.incrementProgressBy(progress [0]); – EvReAzn