无法实例化类错误

时间:2013-06-17 13:32:12

标签: java android android-manifest

这是android清单:         

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/pic"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.thenewboaton.travis.abc"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

         <activity
            android:name="com.thenewboaton.traivs.splash"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.thenewboaton.Splash" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>

</manifest>

名为MainActivity的主java类:

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;




    public class MainActivity extends Activity {

        int counter;
        Button add;
        Button sub;
        TextView display;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);
            counter=0;
            add=(Button)findViewById(R.id.bAdd);
            sub=(Button)findViewById(R.id.bSub); 
            display=(TextView)findViewById(R.id.tvDisplay);
            add.setOnClickListener(new View.OnClickListener() {


                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    counter++;      
                    display.setText("Your total is "+counter);

                }
            });

            sub.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    counter--;
                    display.setText("Your total is "+counter);

                }

             });


        }//method
    }//class

    Finally the logcat:

06-17 18:51:51.427: E/AndroidRuntime(358): FATAL EXCEPTION: main
06-17 18:51:51.427: E/AndroidRuntime(358): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.thenewboaton.travis/com.thenewboaton.travis.abc}: java.lang.ClassNotFoundException: com.thenewboaton.travis.abc in loader dalvik.system.PathClassLoader[/data/app/com.thenewboaton.travis-1.apk]
06-17 18:51:51.427: E/AndroidRuntime(358):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)

所以我尝试在这里和那里改变类名以及活动名称。一旦模拟器启动错误就说Launcher已经失败并且应用程序根本没有启动..我不记得在此错误开始之前我做的确切更改.. 有人可以帮我解决这个问题吗? 如果有人能解决这个问题,我会很高兴的。谢谢:))

2 个答案:

答案 0 :(得分:1)

您需要将AndroidManifest指向MainActivity

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

或者,如果您的Activity被称为 abc splash ,并且位于您的主程序包中,您可以使用:

    <activity
        android:name=".abc"
        android:label="@string/app_name" >
        ...
    </activity>

    <activity
        android:name=".splash"
        android:label="@string/app_name" >
        ...
    </activity>

答案 1 :(得分:-1)

您的清单指向两项活动:&#34; abc&#34;和&#34;泼水&#34;但您的源代码称为MainActivity。将MainActivity重命名为abc或编辑清单以指向MainActivity而不是abc。

相关问题