错误 - 不幸的是,主要活动已停止

时间:2016-02-20 21:05:04

标签: android classnotfoundexception

我开始学习将应用程序开发到Android系统。 我尝试在Netbeans上执行一个简单的Hello World应用程序,但我得到了这个“错误 - 不幸的是,主要活动已停止。”...我不知道为什么......

代码如下......

mainactivity.java

import android.app.Activity;
import android.app.Activity;
import android.app.Activity;
import android.app.Activity;
import android.os.Bundle;
import br.com.bssotware.teste.R;

public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        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:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Hello World, MainActivity"
    />
</LinearLayout>

当我执行它时,我遇到了这个日志错误:

20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime  FATAL EXCEPTION: main
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{br.com.bssotware.teste/br.com.bssotware.teste.MainActivity}: java.lang.ClassNotFoundException: br.com.bssotware.teste.MainActivity
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at android.app.ActivityThread.access$600(ActivityThread.java:130)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at android.os.Handler.dispatchMessage(Handler.java:99)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at android.os.Looper.loop(Looper.java:137)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at android.app.ActivityThread.main(ActivityThread.java:4745)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at java.lang.reflect.Method.invokeNative(Native Method)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at java.lang.reflect.Method.invoke(Method.java:511)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at dalvik.system.NativeStart.main(Native Method)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime  Caused by: java.lang.ClassNotFoundException: br.com.bssotware.teste.MainActivity
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
20:48:52.609    940 br.com.bssotware.teste  ERROR   AndroidRuntime      ... 11 more

Android清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="br.com.bssotware.teste"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <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>
</manifest>

1 个答案:

答案 0 :(得分:1)

删除此行import br.com.bssotware.teste.R;。 然后清理并重建您的项目。