今天学习Android开发突然遇到了这个问题,查阅了很多资料,并且对集中原因进行了分析。

错误信息字符串:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.first/com.first.Game}: java.lang.NullPointerException

一般都会在Activity  onCreate()方法里的setContentView(XXX)发生此错误,网上查阅了很多原因,大概有四种重要可能的原因:

原因一:xxx的错误,若为R.layout.main  那么应该是main.xml文件中的标签 使用错误,最常见的而且编译器不会提示的错误就是 android:name 和 android:id两者混淆,仔细检查main.xml的标签是否全部正确

原因二:在setContentView(view)方法之后使用了requestWindowFeature()方法,并且在此错误下面会提示requestFeature必须在setContentView之前使用,只需要把requestWindowFeature()方法放在setContentView(view)方法之前就可以解决

原因三:在onCreate()方法之外,并且不属于任何一个方法体内直接给某控件findById(R.id.xx)所导致,需要在某方法内并且在setContentView(view)方法之前进行findById(R.id.xx)即可解决

原因四:在setContentView(view)之前没有对view进行实例化,只进行了声明而直接 setContentView(view) 所导致,仔细检查view是否setContentView(view)调用之前并在方法内进行实例化即可解决

原因五:因为发生了空指针的错误异常,所以你应该检查一下比如 Spinner 或者 list 这类的东西里面是否有值存在

转载java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.spinner/com.example.spinner.MainActivity}: java.lang.NullPointerException的更多相关文章

  1. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.love5/com.example.love5.Main11Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.

    若有 java.lang.RuntimeException和 java.lang.NullPointerException: Attempt to invoke virtual method 'voi ...

  2. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.autumn.book/com.autumn.book.MainActivity}: android.os.NetworkOnMainThreadException

    不能把http请求写在主线程里,改为这样 Runnable runnable = new Runnable() { public void run() { HttpClient.post2(" ...

  3. android studio调试报错:java.lang.RuntimeException: Unable to start activity ComponentInfo

    报错信息: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pro_u_loc/com.e ...

  4. bug_ _java.lang.RuntimeException: Unable to start activity ComponentInfo{包名/类名}

      写这篇博文,我顶着很大的压力,贴出来会引来网友的一片鄙视,不贴我又觉得对不起Android SDK研发团队. 本着对全世界Android无产者负责的态度,今天不得不指出Android编译时隐藏的很 ...

  5. Java.lang.RuntimeException: Unable to instantiate activity ComponentInfo

    如果你更新了ADT的新版本,而工程文件中使用了其他的jar包,也可能会出现"java.lang.RuntimeException: Unable to instantiate activit ...

  6. java.lang.RuntimeException: Unable to instantiate activity ComponentInfo异常总结

    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo异常总结 做android开发的可能都碰到"j ...

  7. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.activity/com.ex.activity.LoginActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.activity/com.ex.activity.L ...

  8. java.lang.RuntimeException: Unable to start activity ComponentInfo

    异常:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.william/com.william.Result ...

  9. java.lang.RuntimeException: Unable to start activity ComponentInfo……AppCompat does not support the current theme features

    Android测试时出现闪退的问题,出现了如下所示异常: java.lang.RuntimeException: Unable to start activity ComponentInfo{thon ...

随机推荐

  1. atitit。wondows 右键菜单的管理与位置存储

    atitit.wondows 右键菜单的管理与位置存储 原理 .这样的功能称为Windows外壳扩展(Shell Extensions) 1 常用右键菜单 atiContentMenu1 通用tool ...

  2. python中常用的函数与库一

    1, collections.deque 在python里如果我们用列表作为队列使用也是可以的,只是当从队尾删除或者增加元素的时候是很快的,但是从队首删除或者增加元素则要慢得多,这是因为在队首进行操作 ...

  3. MySQL(五) MySQL中的索引详讲

    序言 之前写到MySQL对表的增删改查(查询最为重要)后,就感觉MySQL就差不多学完了,没有想继续学下去的心态了,原因可能是由于别人的影响,觉得对于MySQL来说,知道了一些复杂的查询,就够了,但是 ...

  4. 对于资源上MissingScript的清理方案讨论

    Unity工程随着复杂度的提升,常会有Prefab上的脚本丢失的情况,如下图所示: 首先失去关联的脚本,是没有线索找到原来是什么文件的,那么有没有办法批处理将这些MissingScript进行一下清理 ...

  5. 了解HTML表单之input元素的23种type类型

    目录 传统类型 text password file radio checkbox hidden button image reset submit 新增类型 color tel email url ...

  6. Hadoop官方文档翻译——YARN Architecture(2.7.3)

    The fundamental idea of YARN is to split up the functionalities of resource management and job sched ...

  7. 云计算之路-阿里云上:消灭“黑色n秒”第三招——禁用网卡的TCP/IP Offload

    程咬金有三板斧,我们有三招.在这篇博文中我们要出第三招,同时也意味着昨天在“希望的田野”上的第二招失败了. 前两招打头(CPU)不凑效,这一招要换一个部位,但依然要坚持攻击敌人最弱(最忙最累)部位的原 ...

  8. 微软Team Foundation Service 的Scrum模板中的Feature和Backlog Items 的区别【转载】

    Features help us plan work better in Team Foundation Service Scrum process [原文:http://www.nsilverbul ...

  9. 构建 iOS 风格移动 Web 应用程序的8款开发框架

    使用 HTML5,CSS3 和 JavaScript 开发移动应用经过实践证明是一种可行的方式.这里收录了几款 iOS 风格的手机应用程序开发框架,帮助您使用擅长的 Web 技术来开发移动应用程序.这 ...

  10. ArcGIS Earth数据小析

    ArcGIS Earth,一款轻量级的三维地球应用.因为工作关系下载试用了半天,正好借这个机会简单研究一下ArcGIS Earth的大概思路,特别是地形数据的组成和影像数据的加载,在这总结整理一下.下 ...