不幸的是,App Name已停止。新手在这里

时间:2014-10-07 04:01:11

标签: android xml eclipse android-manifest

当我试图运行我的Android应用程序。模拟器说不幸的是Appname已经停止。我是新手,我正在按照书中的教程请求帮助。如何修复此错误?

这是清单

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

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

  <application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >
    <activity
        android:name=".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>

logcat错误

10-07 03:30:52.800: I/Process(781): Sending signal. PID: 781 SIG: 9
10-07 03:36:21.560: D/AndroidRuntime(825): Shutting down VM
10-07 03:36:21.570: W/dalvikvm(825): threadid=1: thread exiting with uncaught exception (group=0xb3aded70)
10-07 03:36:21.580: E/AndroidRuntime(825): FATAL EXCEPTION: main
10-07 03:36:21.580: E/AndroidRuntime(825): Process: com.example.hellowworld, PID: 825
10-07 03:36:21.580: E/AndroidRuntime(825): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.hellowworld/com.example.hellowworld}: java.lang.ClassNotFoundException: Didn't find class "com.example.hellowworld" on path: DexPathList[[zip file "/data/app/com.example.hellowworld-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.hellowworld-1, /system/lib]]
10-07 03:36:21.580: E/AndroidRuntime(825):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2123)
10-07 03:36:21.580: E/AndroidRuntime(825):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
10-07 03:36:21.580: E/AndroidRuntime(825):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
10-07 03:36:21.580: E/AndroidRuntime(825):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
10-07 03:36:21.580: E/AndroidRuntime(825):  at android.os.Handler.dispatchMessage(Handler.java:102)
10-07 03:36:21.580: E/AndroidRuntime(825):  at android.os.Looper.loop(Looper.java:136)
10-07 03:36:21.580: E/AndroidRuntime(825):  at android.app.ActivityThread.main(ActivityThread.java:5026)
10-07 03:36:21.580: E/AndroidRuntime(825):  at java.lang.reflect.Method.invokeNative(Native Method)
10-07 03:36:21.580: E/AndroidRuntime(825):  at java.lang.reflect.Method.invoke(Method.java:515)
10-07 03:36:21.580: E/AndroidRuntime(825):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
10-07 03:36:21.580: E/AndroidRuntime(825):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
10-07 03:36:21.580: E/AndroidRuntime(825):  at dalvik.system.NativeStart.main(Native Method)
10-07 03:36:21.580: E/AndroidRuntime(825): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.hellowworld" on path: DexPathList[[zip file "/data/app/com.example.hellowworld-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.hellowworld-1, /system/lib]]
10-07 03:36:21.580: E/AndroidRuntime(825):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
10-07 03:36:21.580: E/AndroidRuntime(825):  at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
10-07 03:36:21.580: E/AndroidRuntime(825):  at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
10-07 03:36:21.580: E/AndroidRuntime(825):  at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-07 03:36:21.580: E/AndroidRuntime(825):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
10-07 03:36:21.580: E/AndroidRuntime(825):  ... 11 more
10-07 03:41:21.720: I/Process(825): Sending signal. PID: 825 SIG: 9
10-07 03:47:53.940: D/AndroidRuntime(877): Shutting down VM

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="com.example.hellowworld.MainActivity" >
</RelativeLayout/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

爪哇

package com.example.hellowworld;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

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) {

        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

2 个答案:

答案 0 :(得分:0)

在Eclipse中执行以下步骤

步骤1.项目→清洁

步骤2.构建并运行您的应用程序。

答案 1 :(得分:0)

在Manifest中尝试使用完整路径名称

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

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

  <application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.hellowworld.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>

清理项目并重新运行