gpt4 book ai didi

android - 运行android示例代码时无法实例化 Activity 组件

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:54:10 26 4
gpt4 key购买 nike

我正在学习 tutorial从安卓网站。

但是当我运行应用程序时,它提示Unable to instantiate activity component,关于classNotFoundException。但是在 manifext.xml 文件中注册了 MainActivity。我不知道问题出在哪里。这是完整的错误日志。

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

list 文件,AbdroidManifest.xml

<!--
Copyright 2012 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

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

<uses-sdk android:minSdkVersion="14" />

<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@android:style/Theme.Holo.Light.DarkActionBar">

<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=".CollectionDemoActivity" android:label="@string/demo_collection" />

</application>
</manifest>

最佳答案

如果我没记错的话,您正在使用 Android 支持库。你是如何将它添加到你的项目中的?如果您在 Java Build Path 中添加,您可能会遇到此异常。

一个建议是从您的构建路径中删除 JAR,然后右键单击您的项目并选择 Android Tools --> Add Support Library

关于android - 运行android示例代码时无法实例化 Activity 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16364050/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com