Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何应对java.lang.RuntimeException:无法启动活动组件信息_Java_Android_Logcat - Fatal编程技术网

如何应对java.lang.RuntimeException:无法启动活动组件信息

如何应对java.lang.RuntimeException:无法启动活动组件信息,java,android,logcat,Java,Android,Logcat,我目前正在学习Java Android SDK。我试图从子活动中获取结果,但无法使setResult()方法正常工作。每次我开始活动,它似乎都不起作用。如何使用调试器查找此问题 08-24 15:00:44.018: E/AndroidRuntime(32400): FATAL EXCEPTION: main 08-24 15:00:44.018: E/AndroidRuntime(32400): Process: com.example.theotherproject, PID: 32400

我目前正在学习Java Android SDK。我试图从子活动中获取结果,但无法使
setResult()
方法正常工作。每次我开始活动,它似乎都不起作用。如何使用调试器查找此问题

08-24 15:00:44.018: E/AndroidRuntime(32400): FATAL EXCEPTION: main
08-24 15:00:44.018: E/AndroidRuntime(32400): Process: com.example.theotherproject, PID: 32400
08-24 15:00:44.018: E/AndroidRuntime(32400): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.theotherproject/com.example.theotherproject.OtherActivity}: java.lang.NullPointerException
08-24 15:00:44.018: E/AndroidRuntime(32400):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at android.app.ActivityThread.access$800(ActivityThread.java:156)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at android.os.Handler.dispatchMessage(Handler.java:102)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at android.os.Looper.loop(Looper.java:157)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at android.app.ActivityThread.main(ActivityThread.java:5872)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at java.lang.reflect.Method.invokeNative(Native Method)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at java.lang.reflect.Method.invoke(Method.java:515)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at dalvik.system.NativeStart.main(Native Method)
08-24 15:00:44.018: E/AndroidRuntime(32400): Caused by: java.lang.NullPointerException
08-24 15:00:44.018: E/AndroidRuntime(32400):    at com.example.theotherproject.OtherActivity.onCreate(OtherActivity.java:34)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at android.app.Activity.performCreate(Activity.java:5312)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
08-24 15:00:44.018: E/AndroidRuntime(32400):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552)
08-24 15:00:44.018: E/AndroidRuntime(32400):    ... 11 more
这是另一项活动

@Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        line = (String) getIntent().getSerializableExtra(TAG);

        textView = (TextView) findViewById(R.id.textView);
        textView.setText(line);

        checkBox = (CheckBox) findViewById(R.id.checkbox);
        checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {


                    checked = isChecked;
                    Intent i = new Intent();
                    i.putExtra(OTHERTAG, checked);
                    setResult(RESULT_OK, i);


            }

        });
我经常在清单中遇到问题,所以如果这是问题的一部分,就在这里

<activity
            android:name="com.example.theotherproject.FirstFragment"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".OtherActivity"
            android:label="@string/app_name">
        </activity>

这里是activity_second.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="157dp"/>

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="64dp"
         />

</RelativeLayout>

添加空意图检查:

if (getIntent() != null) {
    line = (String) getIntent().getSerializableExtra(TAG);
} else {
    Log.e("TAG","Intent was null");
}

您真正的问题在这里:08-24 15:00:44.018:E/AndroidRuntime(32400):由:java.lang.NullPointerException 08-24 15:00:44.018:E/AndroidRuntime(32400):在com.example.theotherproject.OtherActivity.onCreate(OtherActivity.java:34)上发布activity的内容。我已经发布了activty_second.xml