未发现活动异常

时间:2015-07-07 04:29:32

标签: android

  • 我收到activityNotFound Exception.Unable找到显式 活动类。但我已在清单中声明了我的活动。

  • 我搜索了很多关于这个问题的帖子。但是它并没有 解决了我的问题。

堆栈跟踪:

07-06 23:52:27.226: E/AndroidRuntime(7600): FATAL EXCEPTION: main
07-06 23:52:27.226: E/AndroidRuntime(7600): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.stevedata/android.app.ListActivity}; have you declared this activity in your AndroidManifest.xml?
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.app.Activity.startActivityForResult(Activity.java:3390)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.app.Activity.startActivityForResult(Activity.java:3351)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.app.Activity.startActivity(Activity.java:3587)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.app.Activity.startActivity(Activity.java:3555)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at com.example.stevedata.MainActivity$1.onClick(MainActivity.java:38)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.view.View.performClick(View.java:4240)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.view.View$PerformClick.run(View.java:17721)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.os.Handler.handleCallback(Handler.java:730)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.os.Looper.loop(Looper.java:137)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at android.app.ActivityThread.main(ActivityThread.java:5103)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at java.lang.reflect.Method.invokeNative(Native Method)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at java.lang.reflect.Method.invoke(Method.java:525)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-06 23:52:27.226: E/AndroidRuntime(7600):     at dalvik.system.NativeStart.main(Native Method)

MainActivity.java

public class MainActivity extends Activity {


    Button button1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button1=(Button)findViewById(R.id.button1);

        button1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent intent=new Intent(MainActivity.this,ListActivity.class);

                startActivity(intent);

            }
        });

  }

 }

ListActivity.java:

public class ListActivity extends Activity {

    Button button1;

      @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.list_activity);

            button1=(Button)findViewById(R.id.button);
      }
}

清单:

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

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

</application>

任何人都可以帮助我。谢谢。

4 个答案:

答案 0 :(得分:3)

您的ListActivity似乎导入了错误的MainActivity。崩溃表明您正在尝试启动android.app.ListActivity

答案 1 :(得分:2)

您的活动名称是 ListActivity ,这是一个已经安装在android(android.app.ListActivity)上的类。所以重命名类名。

答案 2 :(得分:2)

我认为因为Android SDK存在一个类名ListActivity的根本原因所以Os不知道exaclty需要调用哪个类这种情况。 尝试在javaManifest

中将您的班级重命名为另一个班级

答案 3 :(得分:1)

com.example.stevedata.ListActivity

中导入android.app.ListActivity而不是MainActivity