Android 显式 Intent 抛出 NoClassDefFound 错误

发布于 2024-11-05 01:40:34 字数 1424 浏览 4 评论 0原文

我正在尝试使用明确的意图在我的 Android 应用程序中显示 MapView。虽然我没有发现我的代码有任何问题,但当我尝试启动我的活动时,我不断收到“NoClassDefFoundError”。 基本上,从我的主要活动 (SetCriteria) 中,当用户按下按钮时,我会创建明确的意图:

 Log.i(TAG, "Showing map..");
 try{
   Intent intentMap = new Intent(view.getContext(), AddLocation.class);
   startActivity(intentMap);
}catch(Throwable ex) {
   Log.e(TAG, "Error occured while trying to display map", ex);
}

我的 LogCat 显示:

 java.lang.NoClassDefFoundError: com.adm.AddLocation
 ...
 Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

我的清单如下所示:

<application android:label="@string/app_name" android:icon="@drawable/ic_launcher_red">
    <uses-library android:name="com.google.android.maps"/>              
    <activity android:name=".SetCriteria"
              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=".AddLocation" 
          android:label="@string/add_location">         
    </activity>
</application>

我只有一个包:com.adm。那么可能出了什么问题呢?我使用 Intent(Intent.ACTION_VIEW, uri) 启动地图没有问题,但我希望我的特定活动处理地图。

I'm trying to use an explicit intent to display a MapView in my android app. Although I don't see anything wrong with my code, I keep getting a "NoClassDefFoundError" when I try to start my activity.
Basically, from my main activity (SetCriteria), I create the explicit intent when user presses a button :

 Log.i(TAG, "Showing map..");
 try{
   Intent intentMap = new Intent(view.getContext(), AddLocation.class);
   startActivity(intentMap);
}catch(Throwable ex) {
   Log.e(TAG, "Error occured while trying to display map", ex);
}

My LogCat displays:

 java.lang.NoClassDefFoundError: com.adm.AddLocation
 ...
 Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

My Manifest looks like this:

<application android:label="@string/app_name" android:icon="@drawable/ic_launcher_red">
    <uses-library android:name="com.google.android.maps"/>              
    <activity android:name=".SetCriteria"
              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=".AddLocation" 
          android:label="@string/add_location">         
    </activity>
</application>

I have only one package: com.adm. So what could be wrong? I have no problem launching a map by using Intent(Intent.ACTION_VIEW, uri) but I want my specific activity dealing with the map.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轻拂→两袖风尘 2024-11-12 01:40:34

您应该在第二个活动声明中的类名之前删除“.”(点),因此它看起来像:

<activity android:name="AddLocation" android:label="@string/add_location">

You should remove the "." (dot) before your class name in the second activity declaration, so it would look like:

<activity android:name="AddLocation" android:label="@string/add_location">
娇俏 2024-11-12 01:40:34

从清单片段来看,尚不清楚您定义了哪个包。

您需要将其放在顶级清单元素中:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.adm"
          >

    <application android:icon="@drawable/icon" android:label="@string/app_name" ...

如果您不添加它,系统将不会使用包,并且您的活动“.AddLocation”将以不带类的“AddLocation”结束,它与 com.adm.AddLocation 不同。

From the manifest snippet it is not clear, what package you have defined.

You need to put it in the top-level manifest element:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.adm"
          >

    <application android:icon="@drawable/icon" android:label="@string/app_name" ...

If you do not add that, the system will not use a package and your activity ".AddLocation" will end as "AddLocation" without a class, which is not the same as com.adm.AddLocation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文