许多用户都面临着这种例外。我使用了几个活动和片段,所以我不知道它是从哪里产生的。这绝对与DialogFragment无关,因为我甚至不在我的应用中使用它。
这是完整的堆栈跟踪:
0 java.lang.RuntimeException: Unable to start activity ComponentInfo{project/project.MainActivity}: java.lang.IllegalStateException: Fragment does not have a view
1 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
2 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
3 at android.app.ActivityThread.-wrap11(ActivityThread.java)
4 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
5 at android.os.Handler.dispatchMessage(Handler.java:102)
6 at android.os.Looper.loop(Looper.java:148)
7 at android.app.ActivityThread.main(ActivityThread.java:5443)
8 at java.lang.reflect.Method.invoke(Native Method)
9 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
10 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11 Caused by: java.lang.IllegalStateException: Fragment does not have a view
12 at android.support.v4.app.Fragment$1.onFindViewById(SourceFile:1922)
13 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1057)
14 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1248)
15 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1230)
16 at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:2042)
17 at android.support.v4.app.Fragment.performActivityCreated(SourceFile:1976)
18 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1092)
19 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1248)
20 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1230)
21 at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:2042)
22 at android.support.v4.app.FragmentController.dispatchActivityCreated(SourceFile:165)
23 at android.support.v4.app.FragmentActivity.onStart(SourceFile:543)
24 at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1260)
25 at android.app.Activity.performStart(Activity.java:6261)
26 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
27 ... 9 more
28 java.lang.IllegalStateException: Fragment does not have a view
29 at android.support.v4.app.Fragment$1.onFindViewById(SourceFile:1922)
30 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1057)
31 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1248)
32 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1230)
33 at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:2042)
34 at android.support.v4.app.Fragment.performActivityCreated(SourceFile:1976)
35 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1092)
36 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1248)
37 at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1230)
38 at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:2042)
39 at android.support.v4.app.FragmentController.dispatchActivityCreated(SourceFile:165)
40 at android.support.v4.app.FragmentActivity.onStart(SourceFile:543)
41 at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1260)
42 at android.app.Activity.performStart(Activity.java:6261)
43 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
44 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
45 at android.app.ActivityThread.-wrap11(ActivityThread.java)
46 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
47 at android.os.Handler.dispatchMessage(Handler.java:102)
48 at android.os.Looper.loop(Looper.java:148)
49 at android.app.ActivityThread.main(ActivityThread.java:5443)
50 at java.lang.reflect.Method.invoke(Native Method)
51 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
52 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
知道这个例外是什么?
答案 0 :(得分:-1)
看起来你正在使用MainActivity中的Fragment,并且onCreateView的返回不是有效视图(可能为null)。