2012-12-21 68 views
0

我想從登錄活動切換...我擁有所有的表單,但是當我點擊按鈕時,它就會關閉。開關活動出錯

這是我的代碼。

頭等艙

public class MainActivity extends Activity { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    final EditText pass = (EditText)findViewById(R.id.editText1); 
    final Intent myIntent = new Intent(getApplicationContext(), Menu.class); 

    String mydate = java.text.DateFormat.getDateInstance().format(Calendar.getInstance().getTime()); 

    TextView fecha = (TextView)findViewById(R.id.textView2); 
    fecha.setText(mydate); 

    Button next = (Button) findViewById(R.id. button1); 
    next.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 


      if("12345".equals(pass.getText().toString())) { 
      //Toast.makeText(getApplicationContext(), "Clave Correcta", Toast.LENGTH_SHORT).show(); 

      startActivity(myIntent); 
      } 
      else { 

       Toast.makeText(getApplicationContext(), "Clave Incorrecta", Toast.LENGTH_SHORT).show(); 

      } 
     } 

    }); 

} 

第二類人。

public class Menu extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.menu); 

} 

}

登錄貓:

12-21 17:04:53.710: E/Trace(2389): error opening trace file: No such file or directory (2) 
12-21 17:04:57.680: E/AndroidRuntime(2389): FATAL EXCEPTION: main 
12-21 17:04:57.680: E/AndroidRuntime(2389): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.pizzasjaps/android.view.Menu}; have you declared this activity in your AndroidManifest.xml? 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.app.Activity.startActivityForResult(Activity.java:3351) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.app.Activity.startActivityForResult(Activity.java:3312) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.app.Activity.startActivity(Activity.java:3522) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.app.Activity.startActivity(Activity.java:3490) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at com.example.pizzasjaps.MainActivity$1.onClick(MainActivity.java:39) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.view.View.performClick(View.java:4084) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.view.View$PerformClick.run(View.java:16966) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.os.Handler.handleCallback(Handler.java:615) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.os.Handler.dispatchMessage(Handler.java:92) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.os.Looper.loop(Looper.java:137) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at android.app.ActivityThread.main(ActivityThread.java:4906) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at java.lang.reflect.Method.invoke(Method.java:511) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558) 
12-21 17:04:57.680: E/AndroidRuntime(2389):  at dalvik.system.NativeStart.main(Native Method) 
+2

LogCat總是有幫助:) – AndroidPenguin

回答

1

從你的logcat:使用this

final Intent myIntent = new Intent(getApplicationContext(), Menu.class); 

範圍Menu到適當類(考慮:

Unable to find explicit activity class {com.example.pizzasjaps/android.view.Menu} 

該行正試圖加載類android.view.Menu而不是菜單活動代替getApplicationContext()):

final Intent myIntent = new Intent(this, com.example.pizzasjaps.Menu.class); 
+0

真棒..現在它工作。非常感謝你。 – Tidane

1
if("12345".contentEquals(pass.getText().toString())) 

final Intent myIntent = new Intent(MainActivity.this, Menu.class); 

試試這個?

+0

我改變了..它是一樣的..事實上..我沒有輸入Toast來檢查按鈕是否工作..但它沒關係.. – Tidane

+0

你是否在你的清單中聲明瞭這個活動?我的意思是進入你的AndroidManifest.xml並檢查你提到的活動。 – AndroidPenguin

+0

我確實......但我不知道它是否正確。 – Tidane