我通過意圖傳遞一個包並啓動一個活動,但它未執行。日誌中的例外是無法啓動活動
09-25 21:11:44.514: E/AndroidRuntime(426): FATAL EXCEPTION: main
09-25 21:11:44.514: E/AndroidRuntime(426): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.x.y.httpcommunicationhelper2/com.x.y..httpcommunicationhelper2.logout}: java.lang.NullPointerException.
您能指出錯誤嗎? ?你可以幫忙的代碼是:
//Intent part
if (result != null) {
Intent tokenIntent = new Intent(mContext, tokenActivity.class);
Bundle bundle = new Bundle();
bundle.putString("responsedata", result.substring(result.indexOf("=") + 1, result.length()));
tokenIntent.putExtras(bundle);
startActivity(tokenIntent);
//logout class
public class logout extends Activity {
TextView logouttext;
Bundle bundle2;
Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
mContext = this;
logouttext = (TextView) findViewById(R.id.tvlogout);
bundle2 = getIntent().getExtras();
Log.i("logout - ats token", bundle2.getString("responsedata"));
URLconnector ss = new URLconnector();
ss.execute("url");
}
private class URLconnector extends AsyncTask < String, Void, String > {
@Override
protected String doInBackground(String...urls) {
String response = "";
for (String url: urls) {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
List <NameValuePair> postParameters = new ArrayList <NameValuePair>();
postParameters.add(new BasicNameValuePair("appID", "hjbhjbh"));
postParameters.add(new BasicNameValuePair("atsToken", bundle2.getString("responsedata")));
Log.i("logout - ats token", bundle2.getString("responsedata"));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
postParameters);
httppost.setEntity(formEntity);
HttpResponse logoutresp = httpclient.execute(httppost);
Log.i("Logout response ", logoutresp.toString());
錯誤日誌:
09-25 21:11:44.514: E/AndroidRuntime(426): FATAL EXCEPTION: main
09-25 21:11:44.514: E/AndroidRuntime(426): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.x.y.httpcommunicationhelper2/com.x.y..httpcommunicationhelper2.logout}: java.lang.NullPointerException
09-25 21:11:44.514: E/AndroidRuntime(426): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-25 21:11:44.514: E/AndroidRuntime(426): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-25 21:11:44.514: E/AndroidRuntime(426): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-25 21:11:44.514: E/AndroidRuntime(426): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-25 21:11:44.514: E/AndroidRuntime(426): at android.os.Handler.dispatchMessage(Handler.java:99)
09-25 21:11:44.514: E/AndroidRuntime(426): at android.os.Looper.loop(Looper.java:123)
09-25 21:11:44.514: E/AndroidRuntime(426): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-25 21:11:44.514: E/AndroidRuntime(426): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 21:11:44.514: E/AndroidRuntime(426): at java.lang.reflect.Method.invoke(Method.java:507)
09-25 21:11:44.514: E/AndroidRuntime(426): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-25 21:11:44.514: E/AndroidRuntime(426): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-25 21:11:44.514: E/AndroidRuntime(426): at dalvik.system.NativeStart.main(Native Method)
09-25 21:11:44.514: E/AndroidRuntime(426): Caused by: java.lang.NullPointerException
09-25 21:11:44.514: E/AndroidRuntime(426): at com.x.y.httpcommunicationhelper2.logout.onCreate(logout.java:52)
09-25 21:11:44.514: E/AndroidRuntime(426): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-25 21:11:44.514: E/AndroidRuntime(426): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
什麼是第52行? – Ahmad
你能告訴你如何調用你的註銷活動嗎?是否有可能你的'bundle2'是空的,如果我是正確的看看這裏http://stackoverflow.com/questions/5944503/android-getintent-getextras-returns-null這可能是相關的 – user902383
@Ahmad Log.i (「logout - ats token」,bundle2.getString(「responsedata」)); – androidnoob