Android NoClassDefError(Class使用Google地图)

时间:2013-11-23 00:36:30

标签: java android xml google-maps noclassdeffounderror

这是我第一次在android中使用谷歌地图,但当我导航到显示地图的页面时,我得到了NoClassDefError。

我已经探究了这个的原因,我理解常规Java,但我似乎无法找到问题。

Google-play-services-lib作为我的项目中的库导入,因此在查找Google地图时不会失败(无论如何我都可以告诉你)。

应用程序的其余部分工作正常,只有在加载/导航到此页面时才会出现错误。

LogCat输出:

11-22 19:24:11.555: E/AndroidRuntime(1732): FATAL EXCEPTION: main
11-22 19:24:11.555: E/AndroidRuntime(1732): Process: dcs.aber.ac.uk.cs211.group02, PID: 1732
11-22 19:24:11.555: E/AndroidRuntime(1732): java.lang.NoClassDefFoundError: dcs.aber.ac.uk.cs211.group02.WalkRecording
11-22 19:24:11.555: E/AndroidRuntime(1732):     at dcs.aber.ac.uk.cs211.group02.CreateWalkActivity$1.onClick(CreateWalkActivity.java:39)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at android.view.View.performClick(View.java:4424)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at android.view.View$PerformClick.run(View.java:18383)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at android.os.Handler.handleCallback(Handler.java:733)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at android.os.Handler.dispatchMessage(Handler.java:95)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at android.os.Looper.loop(Looper.java:137)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at android.app.ActivityThread.main(ActivityThread.java:4998)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at java.lang.reflect.Method.invokeNative(Native Method)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at java.lang.reflect.Method.invoke(Method.java:515)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
11-22 19:24:11.555: E/AndroidRuntime(1732):     at dalvik.system.NativeStart.main(Native Method)

控制台输出:

[2013-11-23 00:23:13 - WalkingTours] Android Launch!
[2013-11-23 00:23:13 - WalkingTours] adb is running normally.
[2013-11-23 00:23:13 - WalkingTours] Performing dcs.aber.ac.uk.cs211.group02.StartScreen activity launch
[2013-11-23 00:23:13 - WalkingTours] Automatic Target Mode: using existing emulator 'emulator-5556' running compatible AVD 'googleAPIDevice'
[2013-11-23 00:23:13 - WalkingTours] Uploading WalkingTours.apk onto device 'emulator-5556'
[2013-11-23 00:23:13 - WalkingTours] Installing WalkingTours.apk...
[2013-11-23 00:23:25 - WalkingTours] Success!
[2013-11-23 00:23:25 - WalkingTours] Starting activity dcs.aber.ac.uk.cs211.group02.StartScreen on device emulator-5556
[2013-11-23 00:23:29 - WalkingTours] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=dcs.aber.ac.uk.cs211.group02/.StartScreen }

的manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="dcs.aber.ac.uk.cs211.group02"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <permission
        android:name="dcs.aber.ac.uk.cs211.group02.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <!-- Accessing camera hardware -->
    <!-- putting android.hardware.camera prevents non-camera devices using this app -->
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <uses-permission android:name="dcs.aber.ac.uk.cs211.group02.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="dcs.aber.ac.uk.cs211.group02.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


    <application

        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:logo="@drawable/ic_launcher"
        android:theme="@style/AppTheme" >
        <uses-library
            android:name="com.google.android.maps"
            android:required="true" />

        <activity
            android:name="dcs.aber.ac.uk.cs211.group02.StartScreen"
            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="dcs.aber.ac.uk.cs211.group02.CreateWalkActivity"
            android:label="@string/title_activity_create_walk" >
        </activity>
        <activity
            android:name="dcs.aber.ac.uk.cs211.group02.HelpScreen"
            android:label="@string/title_activity_help_screen" >
        </activity>
        <activity
            android:name="dcs.aber.ac.uk.cs211.group02.WalkRecording"
            android:label="@string/title_activity_walk_recording" >

        </activity>
        <activity
            android:name="dcs.aber.ac.uk.cs211.group02.CreateNewPOIActivity"
            android:label="@string/title_activity_create_new_poi" >
        </activity>
    </application>

    <meta-data
        android:name="dcs.aber.ac.uk.cs211.group02.API_KEY"
        android:value="AIzaSyBKYpKfU4zn-3IBkskKsLbwRsQ1-IqFldk" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

</manifest>

带有错误xml(WalkRecording.xml)

的类
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black"
    tools:context=".WalkRecording" >

    <fragment
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/mapView"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

WalkRecording.java

package dcs.aber.ac.uk.cs211.group02;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class WalkRecording extends FragmentActivity {

    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_walk_recording);
        map=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapView)).getMap();

        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.walk_recording, menu);
        return true;
    }



}

交换到此类的代码:

public void addListenerOnButtons(){

        recordButton = (Button) findViewById(R.id.createWalkButton);
        recordButton.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v){

                Intent intent = new Intent(context, WalkRecording.class);
                startActivity(intent);
            }

        });

我也设置了它,因此gen文件夹位于构建顺序中的源文件夹上方。

2 个答案:

答案 0 :(得分:0)

非常简单的解决方案。我不得不去:

项目&gt;属性&gt;订单和导出删除supportv4.jar clean和build,然后重新添加。

不确定为什么这是一个问题,但现在可行。

答案 1 :(得分:0)

  

NoClassDefFoundError的

表示在运行时未找到某些内容,但在编译时出现。也许在类路径中缺少一些库。