繁体   English   中英

一个简单的hello world android程序中的错误

[英]Error in a simple hello world android program

我刚刚创建了一个简单的hello world程序,看起来所有代码都很好,但是某些东西使android显示“不幸的是,应用程序需要关闭”错误

启动点类的startingPoint.java代码

package demo4;

import com.example.demo4.R;
import android.app.Activity;
import android.os.Bundle;

public class startingPoint extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    }
    }

main.xml,它是启动器类的布局

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



   <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

</LinearLayout>

androidmanifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.demo4"
    android:versionCode="1"
    android:versionName="1.0" >

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

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

这是logcat

    08-30 12:46:22.921: D/AndroidRuntime(326): Shutting down VM
    08-30 12:46:22.941: W/dalvikvm(326): threadid=1: thread exiting with uncaught exception (group=0x40015560)
    08-30 12:46:23.021: E/AndroidRuntime(326): FATAL EXCEPTION: main
    08-30 12:46:23.021: E/AndroidRuntime(326): java.lang.RuntimeException: Unable to instantiate activity       ComponentInfo{com.example.demo4/com.example.demo4.startingPoint}: java.lang.ClassNotFoundException: com.example.demo4.startingPoint in loader dalvik.system.PathClassLoader[/data/app/com.example.demo4-2.apk]
    08-30 12:46:23.021: E/AndroidRuntime(326):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at android.os.Handler.dispatchMessage(Handler.java:99)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at android.os.Looper.loop(Looper.java:123)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at android.app.ActivityThread.main(ActivityThread.java:3683)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at java.lang.reflect.Method.invokeNative(Native Method)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at java.lang.reflect.Method.invoke(Method.java:507)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at dalvik.system.NativeStart.main(Native Method)
    08-30 12:46:23.021: E/AndroidRuntime(326): Caused by: java.lang.ClassNotFoundException: com.example.demo4.startingPoint in loader dalvik.system.PathClassLoader[/data/app/com.example.demo4-2.apk]
    08-30 12:46:23.021: E/AndroidRuntime(326):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    08-30 12:46:23.021: E/AndroidRuntime(326):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
    08-30 12:46:23.021: E/AndroidRuntime(326):  ... 11 more

很喜欢...正如Mtoypc指示的那样。 程序包名称不同,并且没有反映在startingPoint.java中

所以我发表评论作为答案:)

似乎android尝试在包com.example.demo4.startingPoint找到该类,但是在您的代码中,包只是demo4 尝试通过package com.example.demo4.更改第一行package com.example.demo4.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM