[Android] 透過 Intent 切換 Activity 發生 The application has stopped unexceptedly.
2011/02/08
案例很簡單,這問題發生在我有一個 Class – main1 透過Intent 切換至 main2 的時候
一直出現…
程式碼怎麼檢查都沒有錯..
package com.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class main1 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btn=(Button)findViewById(R.id.Button01); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(); intent.setClass(main1.this,main2.class); startActivity(intent); main1.this.finish(); } }); } }
最後找到原因 是因為必須要在 AndroidManifest.xml 中加入一段
<activity android:name=".main2" />
讓AndroidManifest.xml 如下
這樣就可以正常切到 main2 了 …
沒辦法對Android不熟..><
讚一下:
下載:
標籤:
Android
|
This entry was posted on 凌晨1:05
and is filed under
Android
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.
訂閱:
張貼留言 (Atom)
0 意見:
張貼留言