报错java.lang.RuntimeException:xxxx(项目文件目录):xxx ... on a null object reference
Posted 夏同学要努力
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了报错java.lang.RuntimeException:xxxx(项目文件目录):xxx ... on a null object reference相关的知识,希望对你有一定的参考价值。
**
关于android stdio空指针报错
**
Process: com.example.express.g, PID: 11002
java.lang.RuntimeException: Unable to start activity ComponentInfocom.example.express.g/com.example.express.activity.UserMainActivity: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(int)' on a null object reference
at com.example.express.activity.UserMainActivity.setFragment(UserMainActivity.java:77)
at com.example.express.activity.UserMainActivity.onCreate(UserMainActivity.java:40)
at android.app.Activity.performCreate(Activity.java:7994)
at android.app.Activity.performCreate(Activity.java:7978)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
然后呢,小编就发现
这个地方为空值,所以顺着逻辑向上找,发现没有获取控件信息,无语至极
更要命的是,这一次给那个获取控件信息放在使用的后边,也报空指针,无了个大语,真就日八歘。
总结:
一般情况下呢,我们遇到空指针的时候,肯定是某个地方,我们所用到的变量没有告知编译器,他自己不晓得那个东西是啥子,就卡在那里耍脾气,可以通过他那个报错定位或者调试定位到具体的问题处,然后就这样这样,那样那样就over咯。
以上是关于报错java.lang.RuntimeException:xxxx(项目文件目录):xxx ... on a null object reference的主要内容,如果未能解决你的问题,请参考以下文章
Androidjava.lang.IllegalArgumentException: AppCompat does not support the current theme features
Hive 2.3.4 Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
Hive 2.3.4 Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient