尝试通过intent启动mapactivity时获取NoClassDefFoundError

时间:2012-04-18 06:59:35

标签: android android-maps

我是Android的Map View实现的新手。我正在尝试启动一个包含谷歌地图的新活动(点击按钮)。我似乎正在做http://developer.android.com/guide/tutorials/views/hello-mapview.html中提到的所有事情。但是我收到以下错误: -

04-18 12:11:11.332: E/AndroidRuntime(629): FATAL EXCEPTION: main
04-18 12:11:11.332: E/AndroidRuntime(629): java.lang.IllegalStateException: Could not execute method of the activity
04-18 12:11:11.332: E/AndroidRuntime(629):  at android.view.View$1.onClick(View.java:2144)
04-18 12:11:11.332: E/AndroidRuntime(629):  at android.view.View.performClick(View.java:2485)
04-18 12:11:11.332: E/AndroidRuntime(629):  at android.view.View$PerformClick.run(View.java:9080)
04-18 12:11:11.332: E/AndroidRuntime(629):  at android.os.Handler.handleCallback(Handler.java:587)
04-18 12:11:11.332: E/AndroidRuntime(629):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-18 12:11:11.332: E/AndroidRuntime(629):  at android.os.Looper.loop(Looper.java:130)
04-18 12:11:11.332: E/AndroidRuntime(629):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-18 12:11:11.332: E/AndroidRuntime(629):  at java.lang.reflect.Method.invokeNative(Native Method)
04-18 12:11:11.332: E/AndroidRuntime(629):  at java.lang.reflect.Method.invoke(Method.java:507)
04-18 12:11:11.332: E/AndroidRuntime(629):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-18 12:11:11.332: E/AndroidRuntime(629):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-18 12:11:11.332: E/AndroidRuntime(629):  at dalvik.system.NativeStart.main(Native Method)
04-18 12:11:11.332: E/AndroidRuntime(629): Caused by: java.lang.reflect.InvocationTargetException
04-18 12:11:11.332: E/AndroidRuntime(629):  at java.lang.reflect.Method.invokeNative(Native Method)
04-18 12:11:11.332: E/AndroidRuntime(629):  at java.lang.reflect.Method.invoke(Method.java:507)
04-18 12:11:11.332: E/AndroidRuntime(629):  at android.view.View$1.onClick(View.java:2139)
04-18 12:11:11.332: E/AndroidRuntime(629):  ... 11 more
04-18 12:11:11.332: E/AndroidRuntime(629): Caused by: java.lang.NoClassDefFoundError: org.sam.LocationActivity
04-18 12:11:11.332: E/AndroidRuntime(629):  at org.sam.SelfDefActivity.showLocator(SelfDefActivity.java:16)
04-18 12:11:11.332: E/AndroidRuntime(629):  ... 14 more

这是showLocator的方法: -

public void showLocator(View view) {
    Intent i = new Intent(SelfDefActivity.this, LocationActivity.class);
    final int result=1;
    startActivityForResult(i, result);
    finish();
}

这就是我的清单: -

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.sam"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            android:name=".SelfDefActivity"
            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=".LocationActivity"
            android:label="@string/location_activity" >
            <uses-library android:name="com.google.android.maps" />
        </activity>
    </application>

</manifest>

有谁能告诉我哪里出错了?

2 个答案:

答案 0 :(得分:9)

在清单文件中添加活动的完整路径

喜欢android:name="your package name.LocationActivity"

由于您的活动名称建议您检查位置,因此您应该添加相应的权限,如下所示

你的清单应该是

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.sam"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            android:name=".SelfDefActivity"
            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=".LocationActivity"
            android:label="@string/location_activity" >   
        </activity>
        <uses-library android:name="com.google.android.maps" />
    </application>

</manifest>

答案 1 :(得分:0)

你这个类型

</application>
         <activity
          ......
          .....

         </activity>

 <uses-library android:name="com.google.android.maps" />

</application>