我得到了一个>非常<简单的程序,当我尝试更改活动时崩溃。 在我的fragment_app_launch.xml上只有一个Button(id:question_cat_button_1):
AppLaunch.java
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_app_launch,
container, false);
Button b = (Button)rootView.findViewById(R.id.question_cat_button_1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("com.pthuermer.juraQuiz.QuizActivity");
startActivity(intent);
}
});
return rootView;
}
AndroidManifest:
<activity
android:name="com.pthuermer.juraquiz.QuizActivity"
android:label="@string/title_activity_quiz" >
</activity>
logcat的误差:
03-13 21:09:54.602: E/AndroidRuntime(13753): FATAL EXCEPTION: main
03-13 21:09:54.602: E/AndroidRuntime(13753): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.pthuermer.juraQuiz.QuizActivity }
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1671)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1441)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.app.Activity.startActivityForResult(Activity.java:3464)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.app.Activity.startActivityForResult(Activity.java:3425)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:848)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.support.v4.app.Fragment.startActivity(Fragment.java:878)
03-13 21:09:54.602: E/AndroidRuntime(13753): at com.pthuermer.juraquiz.AppLaunch$PlaceholderFragment$1.onClick(AppLaunch.java:75)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.view.View.performClick(View.java:4475)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.view.View$PerformClick.run(View.java:18786)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.os.Handler.handleCallback(Handler.java:730)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.os.Handler.dispatchMessage(Handler.java:92)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.os.Looper.loop(Looper.java:137)
03-13 21:09:54.602: E/AndroidRuntime(13753): at android.app.ActivityThread.main(ActivityThread.java:5419)
03-13 21:09:54.602: E/AndroidRuntime(13753): at java.lang.reflect.Method.invokeNative(Native Method)
03-13 21:09:54.602: E/AndroidRuntime(13753): at java.lang.reflect.Method.invoke(Method.java:525)
03-13 21:09:54.602: E/AndroidRuntime(13753): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
03-13 21:09:54.602: E/AndroidRuntime(13753): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
03-13 21:09:54.602: E/AndroidRuntime(13753): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
更改
Intent intent = new Intent("com.pthuermer.juraQuiz.QuizActivity");
到
Intent intent = new Intent("com.pthuermer.juraquiz.QuizActivity");
小&#34; q&#34;
Differences in implicit and explicit Intents
您可以通过搜索Google轻松找到很多关于隐式Intents
的内容,但通常是在您自己的应用内启动Activity
,您可以使用明确的Intent
更容易获得它起作用。
答案 1 :(得分:0)
Java区分大小写,因此com.pthuermer.juraquiz.QuizActivity
和com.pthuermer.juraQuiz.QuizActivity
不一样,这就是您获得ActivityNotFoundException
的原因。它应该是:
Intent intent = new Intent("com.pthuermer.juraQuiz.QuizActivity");
startActivity(intent);
答案 2 :(得分:0)
您将意图的操作设置为"com.pthuermer.juraQuiz.QuizActivity"
。
我想你想使用http://developer.android.com/reference/android/content/Intent.html#setClassName(java.lang.String,java.lang.String)。
答案 3 :(得分:0)
嘿,改变你对此的意图
Intent intent = new Intent(getApplicationContext(),com.pthuermer.juraquiz.QuizActivity.class);