下面的代碼是一個Button的onClick()
方法。
它不斷給我一個錯誤。
如果我刪除startActivity()
,那麼它工作正常。如何在一個onClick方法中添加兩個函數?
我怎樣才能使用POST方法,當我點擊按鈕,也移動到另一個活動?
public void onClick(View view) {
switch (view.getId()) {
case R.id.register:
if (!validate())
Toast.makeText(getBaseContext(), "Enter user information!", Toast.LENGTH_LONG).show();
// call AsynTask to perform network operation on separate thread
new HttpAsyncTask().execute(herokuServer);
startActivity(new Intent(this, FoodPreference.class));
break;
}
startActivity(new Intent(Register1Activity.this, FoodPreference.class));
}
THE ERROR: 04-27 19:41:26.066 1974-1974/com.opshun_test.opshun_test E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.opshun_test.opshun_test, PID: 1974 android.content.ActivityNotFoundException: Unable to find explicit activity class {com.opshun_test.opshun_test/com.opshun_test.opshun_test.FoodPreference}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1761) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1485) at android.app.Activity.startActivityForResult(Activity.java:3736) at android.app.Activity.startActivityForResult(Activity.java:3697) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817) at android.app.Activity.startActivity(Activity.java:4007) at android.app.Activity.startActivity(Activity.java:3975) at com.opshun_test.opshun_test.Register1Activity.onClick(Register1Activity.java:173) at android.view.View.performClick(View.java:4756) at android.view.View$PerformClick.run(View.java:19749) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 04-27 19:41:26.106 1974-2307/com.opshun_test.opshun_test I/output﹕ [email protected]
通過ERROR更好
Intent
到FoodPreference.class
,我的意思是,當我按一下按鈕,它將停止應用程序。 – chrsfang你會得到什麼樣的錯誤?你可以發佈stacktrace嗎? – AndroidEx
所以「你是否在AndroidManifest.xml中聲明瞭這個活動?」 :) – AndroidEx