2016-08-04 68 views
-1

我有一個問題 「@Topic」Android的工作室和多個按鈕

這是我代碼:

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

    Button one = (Button) findViewById(R.id.button3); 
    one.setOnClickListener(this); // calling onClick() method 
    Button two = (Button) findViewById(R.id.button4); 
    two.setOnClickListener(this); 
    Button three = (Button) findViewById(R.id.button5); 
    three.setOnClickListener(this); 
    Button four = (Button) findViewById(R.id.button1); 
    four.setOnClickListener(this); 
} 

    public void onClick(View v) { 

     switch (v.getId()) { 

      case R.id.button3: 
       Intent i = new Intent(this, MainActivity.class); 
       startActivity(i); 
       break; 

      case R.id.button4: 
       Intent intent = new Intent(this, NewTwo.class); 
       startActivity(intent); 
       break; 

      case R.id.button5: 
       Intent intent_two = new Intent(this, NewThree.class); 
       startActivity(intent_two); 
       break; 

      case R.id.button1: 
       Intent intent_three = new Intent(this, NewFour.class); 
       Toast.makeText(getApplicationContext(), "Praca w toku...", Toast.LENGTH_LONG).show(); 

       startActivity(intent_three); 
       break; 

      default: 
       break; 
     } 

    } 

它是日誌錯誤:

08-04 12:35:08.852 596-596/com.example.tomecki.alarmclock E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.tomecki.alarmclock, PID: 596 android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.tomecki.alarmclock/com.example.tomecki.alarmclock.NewTimer}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501) at android.app.Activity.startActivityForResult(Activity.java:3843) at android.app.Activity.startActivityForResult(Activity.java:3797) at android.app.Activity.startActivity(Activity.java:4114) at android.app.Activity.startActivity(Activity.java:4082) at com.example.tomecki.alarmclock.MainActivity.onClick(MainActivity.java:41) at android.view.View.performClick(View.java:4793) at android.view.View$PerformClick.run(View.java:19971) 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:5669) 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:960) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

41行是:

case R.id.button4: 
       Intent intent = new Intent(this, NewTimer.class); 
---------->>> startActivity(intent); 
       break; 

請幫助我。)

+0

「你是否在你的AndroidManifest.xml中聲明瞭這個活動?」 – Egor

回答

0

它說,在你的日誌:有你在AndroidManifest.xml中

轉到您的AndroidManifest.xml宣佈這項活動,像這樣的應用程序標籤下添加您的活動:

<activity 
     android:name=".NewTimer" />