简体   繁体   English

线程:崩溃并显示消息“ java.lang.RuntimeException:无法实例化活动”

[英]Thread : Crash with the message “java.lang.RuntimeException: Unable to instantiate activity”

i know this question has been treated so much time, but i really don't find the answer to my problem. 我知道这个问题已经治疗了很多时间,但是我确实找不到解决我问题的答案。 This is an application which connect to a server, so, there's a socket, that's why i'm using thread (i can't do anything else since android 4.0), but even if i'm disable the code of my socket, it still crash. 这是一个连接到服务器的应用程序,因此有一个套接字,这就是为什么我使用线程(自android 4.0以来我什么也不能做)的原因,但是即使我禁用了套接字的代码,它仍然崩溃。

Here's the logCat error : 这是logCat错误:

04-08 08:36:39.366: D/AndroidRuntime(16604): Shutting down VM
04-08 08:36:39.366: W/dalvikvm(16604): threadid=1: thread exiting with uncaught                exception (group=0x4122f300)
04-08 08:36:39.366: E/AndroidRuntime(16604): FATAL EXCEPTION: main
04-08 08:36:39.366: E/AndroidRuntime(16604): java.lang.RuntimeException: Unable to   instantiate activity   ComponentInfo{com.example.projetlyres2013/com.example.projetlyres2013.PlanDMX}:   java.lang.NullPointerException
04-08 08:36:39.366: E/AndroidRuntime(16604):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at android.os.Looper.loop(Looper.java:137)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at android.app.ActivityThread.main(ActivityThread.java:4745)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at java.lang.reflect.Method.invokeNative(Native Method)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at java.lang.reflect.Method.invoke(Method.java:511)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at dalvik.system.NativeStart.main(Native Method)
04-08 08:36:39.366: E/AndroidRuntime(16604): Caused by: java.lang.NullPointerException
04-08 08:36:39.366: E/AndroidRuntime(16604):    at android.app.Activity.findViewById(Activity.java:1825)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at com.example.projetlyres2013.PlanDMX.<init>(PlanDMX.java:27)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at java.lang.Class.newInstanceImpl(Native Method)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at java.lang.Class.newInstance(Class.java:1319)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
04-08 08:36:39.366: E/AndroidRuntime(16604):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
04-08 08:36:39.366: E/AndroidRuntime(16604):    ... 11 more
04-08 08:36:41.326: I/Process(16604): Sending signal. PID: 16604 SIG: 9
04-08 08:46:26.556: D/AndroidRuntime(16825): Shutting down VM

///////// Manifest ///////// //////////清单/////////

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.projetlyres2013"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.projetlyres2013.PlanDMX"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

</manifest>

I don't know what's happened when i want to launch it on my tablet (android 4.1). 我不知道要在平板电脑(android 4.1)上启动它时发生了什么。 I really need help for that :/ 我真的需要帮助:/

Thanks 谢谢

NullPointer here means that you did not set your layout XML as contentView to your Activity. 这里的NullPointer意味着您没有将布局XML设置为Activity的contentView。 Inside onCreate(...) method of Activity add 在Activity的onCreate(...)方法内部

setContentView(R.layout.some_layout-file)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM