不幸的是,"应用程序名称"已停止 - 跟着教程 [英] Unfortunately, "app name here" has stopped - followed tutorial
问题描述
首先,我跟着这个教程:
To begin with, I followed this tutorial:
<一个href=\"http://www.$c$cproject.com/Articles/102065/Android-A-beginner-s-guide?fid=1583614&df=90&mpp=10&noise=1&prof=True&sort=Position&view=Expanded&spc=None&fr=11#xx0xx\" rel=\"nofollow\">http://www.$c$cproject.com/Articles/102065/Android-A-beginner-s-guide?fid=1583614&df=90&mpp=10&noise=1&prof=True&sort=Position&view=Expanded&spc=None&fr=11#xx0xx
我已签了良好这里很多类似的帖子,但所有的解决方案都已经code比,并没有奏效。
I have checked a good many of the similar posts here, but all of the solutions have been code specific and haven't worked.
我刚开始开发Android应用程序,并发现本教程。当我虽然启动它,模拟器给我的这个应用程序已经停止的消息。有没有从我的code警告,所以我甚至不知道从哪里开始。
I am just starting out developing android apps, and found this tutorial. When I launch it though, the emulator gives me the this app has stopped message. There are no warnings from my code, so I don't even know where to begin.
下面是我的code:
MainActivity.java
Here's my code: MainActivity.java
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
//return true;
//get the two controls we created earlier, also with the resource reference and the id
final TextView lv_View = (TextView)findViewById(R.id.lv_View);
lv_View.setText("4");
final EditText et_Text = (EditText)findViewById(R.id.et_Text);
//add new KeyListener Callback (to record key input)
et_Text.setOnKeyListener(new View.OnKeyListener()
{
//function to invoke when a key is pressed
public boolean onKey(View v, int keyCode, KeyEvent event)
{
//check if there is
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
//check if the right key was pressed
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
{
//add the text to the text view
lv_View.setText(lv_View.getText() + ", " +
et_Text.getText());
//and clear the EditText control
et_Text.setText("");
return true;
}
}
return false;
}
});
return true;
}
}
测试清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.test.MainActivity"
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>
的strings.xml
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">test</string>
<string name="hello_world">"I got it to work!"</string>
<string name="menu_settings">Settings</string>
</resources>
activity_main.xml中(布局)
activity_main.xml (layout)
<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"
tools:context=".MainActivity"
>
<edittext android:layout_height="wrap_content"
android:layout_width="fill_parent" android:textColor="#FF0000FF"
android:id="@+id/et_Text" />
<textview android:layout_height="wrap_content" android:layout_width="fill_parent"
android:textColor="#FF00FF00" android:id="@+id/lv_View" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#FF00FF00"
android:text="@string/hello_world"
/>
</RelativeLayout>
LogCat中报告
LogCat report
12-18 21:34:37.873: W/Trace(713): Unexpected value from nativeGetEnabledTags: 0
12-18 21:34:38.442: W/Trace(713): Unexpected value from nativeGetEnabledTags: 0
12-18 21:34:38.522: W/Trace(713): Unexpected value from nativeGetEnabledTags: 0
12-18 21:34:39.562: D/AndroidRuntime(713): Shutting down VM
12-18 21:34:39.602: W/dalvikvm(713): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
12-18 21:34:39.812: E/AndroidRuntime(713): FATAL EXCEPTION: main
12-18 21:34:39.812: E/AndroidRuntime(713): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class edittext
12-18 21:34:39.812: E/AndroidRuntime(713): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.os.Looper.loop(Looper.java:137)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-18 21:34:39.812: E/AndroidRuntime(713): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 21:34:39.812: E/AndroidRuntime(713): at java.lang.reflect.Method.invoke(Method.java:511)
12-18 21:34:39.812: E/AndroidRuntime(713): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-18 21:34:39.812: E/AndroidRuntime(713): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-18 21:34:39.812: E/AndroidRuntime(713): at dalvik.system.NativeStart.main(Native Method)
12-18 21:34:39.812: E/AndroidRuntime(713): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class edittext
12-18 21:34:39.812: E/AndroidRuntime(713): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-18 21:34:39.812: E/AndroidRuntime(713): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.app.Activity.setContentView(Activity.java:1881)
12-18 21:34:39.812: E/AndroidRuntime(713): at com.example.test.MainActivity.onCreate(MainActivity.java:17)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.app.Activity.performCreate(Activity.java:5104)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-18 21:34:39.812: E/AndroidRuntime(713): ... 11 more
12-18 21:34:39.812: E/AndroidRuntime(713): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.edittext" on path: /data/app/com.example.test-2.apk
12-18 21:34:39.812: E/AndroidRuntime(713): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
12-18 21:34:39.812: E/AndroidRuntime(713): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-18 21:34:39.812: E/AndroidRuntime(713): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
12-18 21:34:39.812: E/AndroidRuntime(713): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
12-18 21:34:39.812: E/AndroidRuntime(713): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
12-18 21:34:39.812: E/AndroidRuntime(713): ... 21 more
任何帮助的感谢!如果您需要了解更多信息,只是让我知道。我仍然不知道什么是需要麻烦拍摄这些类型的错误。
Thanks for any help! If you need any more information, just let me know. I'm still not sure of what's needed to trouble shoot these kinds of errors.
推荐答案
在您的布局XML文件中,你需要确保的TextView
和的EditText
的首字母大写,否则Android将不知道如何膨胀的布局。这是因为机器人布局充气通过使用XML文件中specifed名试图实例的类。在这种情况下, android.view.TextView
和 android.view.EditText
。
In your layout XML file, you need to ensure that textview
and edittext
are CamelCase otherwise android will not know how to inflate the layout. This is because the android layout inflater attempts to instance a class by using the name specifed in the XML file. In this case, android.view.TextView
and android.view.EditText
.
<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"
tools:context=".MainActivity">
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textColor="#FF0000FF"
android:id="@+id/et_Text" />
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textColor="#FF00FF00"
android:id="@+id/lv_View" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#FF00FF00"
android:text="@string/hello_world" />
</RelativeLayout>
这篇关于不幸的是,&QUOT;应用程序名称&QUOT;已停止 - 跟着教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!