Android setContentView布局空指针异常

直接就崩掉 烦死了,以前出现过这问题,后来解决了,然后就忘记了。现在又出现这问题越是着急赶项目越是出乱子。巨烦。
今天记录下来 免得以后又翻半天度娘。
爆出的异常是这样的:


E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.sm.zhongketui2, PID: 27884
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sm.zhongketui2/com.sm.zhongketui2.activity.CenterActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2404)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466)
                      at android.app.ActivityThread.access$900(ActivityThread.java:175)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:135)
                      at android.app.ActivityThread.main(ActivityThread.java:5418)
                      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:1037)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
                   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:760)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:851)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:510)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:420)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:371)
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                      at com.sm.zhongketui2.activity.base.BaseActivity2.onCreate(BaseActivity2.java:36)
                      at android.app.Activity.performCreate(Activity.java:6083)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1115)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2357)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466) 
                      at android.app.ActivityThread.access$900(ActivityThread.java:175) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:135) 
                      at android.app.ActivityThread.main(ActivityThread.java:5418) 
                      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:1037) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832) 
Application terminated.

提示onCreate方法的里面的setContentView(provideLayoutId());
原因是布局文件里面有View控件字母大小写写错了:
错误写法:

<view
     android:layout_width="1dp"
     android:layout_height="38dp" />

正确写法:

<View
     android:layout_width="1dp"
     android:layout_height="38dp" />

该写成“View”。结果我把开头字母大写写成了小写“view”。
改成大写“View”就好了。

你可能感兴趣的:(TIP常识)