在android中简单的你好世界

时间:2014-04-17 11:11:44

标签: android android-activity xml-layout

我创建了一个空的android项目。然后我添加一个新的xml布局文件,其中包含以下内容:activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/first_page"
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">    
</RelativeLayout>

并添加一个java类:MainActivity.java

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

public class MainActivity extends Activity
{
    @Override   
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); 
    }
}

AndroidManifest.xml的内容如下:

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity  android:name="com.worldcup2014.MainActivity"
            android:label="@string/app_name" 
            android:screenOrientation="portrait">            
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

当我在模拟设备上运行它时(使用此配置:Nexus One 4.4.2,API 19,CPU ARM)有很多运行时错误。并在logcat中显示:

04-17 06:45:23.300: E/AndroidRuntime(1448): FATAL EXCEPTION: main
04-17 06:45:23.300: E/AndroidRuntime(1448): Process: com.worldcup2014, PID: 1448
04-17 06:45:23.300: E/AndroidRuntime(1448): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.worldcup2014/com.worldcup2014.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.worldcup2014.MainActivity" on path: DexPathList[[zip file "/data/app/com.worldcup2014-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.worldcup2014-1, /system/lib]]
04-17 06:45:23.300: E/AndroidRuntime(1448):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)

.....

1 个答案:

答案 0 :(得分:0)

从模拟设备卸载应用程序和/或清除模拟器。其中一个应该解决你的问题

相关问题