0

我创建了一个 android 应用程序,它从一个活动中获取一些输入并在下一个活动中打印它。应用程序在尝试进入下一个活动时崩溃。问题出在 XML 中,但我不知道在哪里。

最后的活动:

package com.example.competitionapp;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ConfirmationActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third);

        Bundle extras = getIntent().getExtras();

        TextView textViewName = (TextView)findViewById(R.id.textViewLabelName);
        TextView textViewSurname = (TextView)findViewById(R.id.textViewLabelSurname);


        if(extras !=null) {
            String nameValue = extras.getString("name");
            String surnameValue = extras.getString("surname");


            textViewName.setText(nameValue);
            textViewSurname.setText(surnameValue);
    }


}
}

这是xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:background="@drawable/bg2"
     >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="55dp"
        android:text="@string/thanks"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="86dp"
        android:text="@string/gl"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textViewLabelName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/textViewLabelSurname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textViewLabelName"
        android:layout_below="@+id/textViewLabelName"
        android:layout_marginTop="17dp"
        android:text="TextView" />



</RelativeLayout>

和我的日志猫:

   10-24 08:50:01.823: E/AndroidRuntime(840): FATAL EXCEPTION: main
   10-24 08:50:01.823: E/AndroidRuntime(840): java.lang.RuntimeException: Unable to start      activity ComponentInfo{com.example.competitionapp/com.example.competitionapp.ConfirmationActivity}:
   android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
4

1 回答 1

0

也许改变:

工具:上下文=“.MainActivity”

工具:context=".ConfirmationActivity"

于 2013-10-24T13:42:35.933 回答