Android:不幸的是(项目名称)已停止工作

时间:2013-10-30 19:11:16

标签: android android-layout android-intent

•将显示预定义问题的区域 •一个按钮,当问题出现在屏幕上时,将显示问题的答案 •将提供答案的区域 •一个按钮,它将导致转换到与此屏幕格式相同的屏幕,并显示下一个问题 •一个按钮,它将导致应用程序结束(转换为(3))

我正在尝试完成的工作,当我运行程序时出现错误,我将提供logcat。我是android编程的新手,所以在某个地方可能是一个愚蠢的错误。

唯一应该工作的是通过按下按钮从1个问题转换到下一个问题,仅此而已。只完成了2/5。

    10-30 14:20:27.646: D/AndroidRuntime(769): Shutting down VM
10-30 14:20:27.646: W/dalvikvm(769): threadid=1: thread exiting with uncaught exception (group=0x41465700)
10-30 14:20:27.706: E/AndroidRuntime(769): FATAL EXCEPTION: main
10-30 14:20:27.706: E/AndroidRuntime(769): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidassignment2/com.example.androidassignment2.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class Textview
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.os.Looper.loop(Looper.java:137)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.app.ActivityThread.main(ActivityThread.java:5103)
10-30 14:20:27.706: E/AndroidRuntime(769):  at java.lang.reflect.Method.invokeNative(Native Method)
10-30 14:20:27.706: E/AndroidRuntime(769):  at java.lang.reflect.Method.invoke(Method.java:525)
10-30 14:20:27.706: E/AndroidRuntime(769):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-30 14:20:27.706: E/AndroidRuntime(769):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-30 14:20:27.706: E/AndroidRuntime(769):  at dalvik.system.NativeStart.main(Native Method)
10-30 14:20:27.706: E/AndroidRuntime(769): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class Textview
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-30 14:20:27.706: E/AndroidRuntime(769):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.app.Activity.setContentView(Activity.java:1895)
10-30 14:20:27.706: E/AndroidRuntime(769):  at com.example.androidassignment2.MainActivity.onCreate(MainActivity.java:23)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.app.Activity.performCreate(Activity.java:5133)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-30 14:20:27.706: E/AndroidRuntime(769):  ... 11 more
10-30 14:20:27.706: E/AndroidRuntime(769): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.Textview" on path: DexPathList[[zip file "/data/app/com.example.androidassignment2-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.androidassignment2-1, /system/lib]]
10-30 14:20:27.706: E/AndroidRuntime(769):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
10-30 14:20:27.706: E/AndroidRuntime(769):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-30 14:20:27.706: E/AndroidRuntime(769):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.view.LayoutInflater.createView(LayoutInflater.java:559)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
10-30 14:20:27.706: E/AndroidRuntime(769):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
10-30 14:20:27.706: E/AndroidRuntime(769):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
10-30 14:20:27.706: E/AndroidRuntime(769):  ... 21 more
10-30 14:20:32.196: I/Process(769): Sending signal. PID: 769 SIG: 9

屏幕1

package com.example.androidassignment2;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.content.Intent;




public class MainActivity extends Activity {






    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Button next = (Button) findViewById(R.id.QButton);
        next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), AndroidAssignment2_1.class);
                startActivityForResult(myIntent, 0);
            }
        });

    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }



 }

屏幕2

package com.example.androidassignment2;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.content.Intent;

public class AndroidAssignment2_1 extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_android_assignment2_1);

        Button next = (Button) findViewById(R.id.QButton);
        next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                finish();
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.android_assignment2_1, menu);
        return true;
    }

}

xml for 1和2大部分相同。

<LinearLayout 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:orientation="vertical" >

<Textview android:id="@+id/Questions"
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:text="@string/Q1"   />

<Button android:id="@+id/QButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_question" />

<Button android:id="@+id/AButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send" />

<Textview android:id="@+id/Answers"
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:hint="@string/A1" />

<Button android:id="@+id/QuitButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_quit" />


</LinearLayout>



<LinearLayout 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:orientation="vertical" >

<Textview android:id="@+id/Questions"
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:text="@string/Q2"   />

<Button android:id="@+id/QButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_question"  />

<Button android:id="@+id/AButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send" />

<Textview android:id="@+id/Answers"
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:hint="@string/A2" />

<Button android:id="@+id/QuitButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_quit" />


</LinearLayout>

2 个答案:

答案 0 :(得分:6)

更改

<Textview android:id="@+id/Questions"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:text="@string/Q1"   />

 <TextView android:id="@+id/Questions"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:text="@string/Q1"   />

请注意TextView

的拼写

以下行的最后一部分说它不能给类Textview充气,我们知道原因是因为这不是该类的实际拼写

10-30 14:20:27.706: E/AndroidRuntime(769): java.lang.RuntimeException: 
Unable to start activity ComponentInfo
{com.example.androidassignment2/com.example.androidassignment2.MainActivity}: 
android.view.InflateException: 
Binary XML file line #7: Error inflating class Textview    / this part here

将所有TextView更改为正确的拼写。

答案 1 :(得分:2)

XML布局文件中拼写为TextView而不是Textview