我有強制關閉和i的清單的Android片段意圖按鈕旁邊活性
公共類MainActivity寄存器SecondActivity延伸片段{
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view=inflater.inflate(R.layout.activity_main, container,false);
Button mButton=(Button) view.findViewById(R.id.button1);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent mIntent=new Intent(getActivity(),SecondActivity.class);
getActivity().startActivity(mIntent);
}
});
return view;
}
}
logcat的
11-21 17:25:03.277: D/AndroidRuntime(382):關閉虛擬機 11-21 17:25:03.277:W/dalvikvm(382):threadid = 1:線程退出時未捕獲的異常(組= 0x4001d800) 11-21 17:25:03.297 :E/AndroidRuntime(382):致命例外:main 11-21 17:25:03.297:E/AndroidRuntime(382):java.lang.RuntimeException:無法實例化活動ComponentInfo {com.example.star/com.example.star.MainActivity}:java.lang.ClassCastException: com.example.star.MainActivity 11-21 17:25:03.297:E/AndroidRuntime(382):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585) 11-21 17:25:03.297:E/AndroidRuntime(382):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 11-21 17:25:03.297:E/AndroidRuntime(382):at android.app.ActivityThread.access $ 2300(ActivityThread。 java:125) 11-21 17:25:03.297:E/AndroidRuntime(382):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033) 11-21 17:25:03.297:E/AndroidRuntime(382):at android.os.Handler.dispatchMessage(Handler.java:99) 11-21 17:25:03.297:E/AndroidRuntime(382):at android.os.Looper.loop(Looper.java:123) 11-21 17:25:03.297:E/AndroidRuntime(382):at android.app.ActivityThread.main(ActivityThread.java:4627) 11-21 17:25:03.297:E/AndroidRuntime(382):at java.lang.reflect.Method.invokeNative(Native Method) 11-21 17 :25:03.297:E/AndroidRuntime(382):at java.lang.reflect.Method.invoke(Method.java:521) 11-21 17:25:03.297:E/AndroidRuntime(382):at com.android .internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) 11-21 17:25:03.297:E/AndroidRuntime(382):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java :626) 11-21 17:25:03.297:E/AndroidRuntime(382):at dalvik.system.NativeStart.main(Native Method) 11-21 17:25:03.297:E/AndroidRuntime(382):Caused通過:jav a.lang.ClassCastException:com.example.star.MainActivity 11-21 17:25:03.297:E/AndroidRuntime(382):at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 11-21 17 :25:03.297:E/AndroidRuntime(382):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577) 11-21 17:25:03.297:E/AndroidRuntime(382):... 11更多
請在此處添加您的Log貓,以便我們可以更好地瞭解問題所在。 – 2014-11-21 06:54:41
MainActivity中存在ClassCastException:由java.lang.ClassCastException:com.example.star引發。MainActivity 11-21 – 2014-11-21 14:57:27
im beginer我可以修復? – mansour 2014-11-21 15:04:12