构建Google Maps API v2应用程序,但遗憾的是.app已停止工作

时间:2014-12-05 18:34:59

标签: android google-maps google-maps-android-api-2

我正在尝试使用Google Maps API v2构建应用程序,但事实是,应用程序一直给我错误。不幸的是.apk已停止工作,尽管我遵循了所有必需的说明。请查看我的代码并帮助我找出问题所在。在此先感谢

这是我的应用代码

package com.example.ugoogle;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class MainActivity extends MapActivity {

    MapView maps;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        maps = (MapView) findViewById (R.id.MapsViewMain);
        maps.setBuiltInZoomControls(true);
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}

这是我的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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.ugoogle.MainActivity" >


     <com.google.android.gms.maps.MapView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="My key that was generated on google is here. trust me"
        android:id="@+id/MapsViewMain"
        android:enabled="true"
        android:clickable="true"
        />

</RelativeLayout>

这是我的清单

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <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" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

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

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

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="My key that was generated on google is here. trust me" />
    </application>

</manifest>

logcat的

01-01 22:13:31.862: E/AndroidRuntime(13016): FATAL EXCEPTION: main
01-01 22:13:31.862: E/AndroidRuntime(13016): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.vogella.android.locationapi.maps/com.vogella.android.locationapi.maps.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.vogella.android.locationapi.maps.MainActivity" on path: DexPathList[[zip file "/data/app/com.vogella.android.locationapi.maps-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.vogella.android.locationapi.maps-1, /vendor/lib, /system/lib]]
01-01 22:13:31.862: E/AndroidRuntime(13016):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at android.app.ActivityThread.access$600(ActivityThread.java:162)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at android.os.Handler.dispatchMessage(Handler.java:107)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at android.os.Looper.loop(Looper.java:194)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at android.app.ActivityThread.main(ActivityThread.java:5371)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at java.lang.reflect.Method.invokeNative(Native Method)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at java.lang.reflect.Method.invoke(Method.java:525)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at dalvik.system.NativeStart.main(Native Method)
01-01 22:13:31.862: E/AndroidRuntime(13016): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.vogella.android.locationapi.maps.MainActivity" on path: DexPathList[[zip file "/data/app/com.vogella.android.locationapi.maps-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.vogella.android.locationapi.maps-1, /vendor/lib, /system/lib]]
01-01 22:13:31.862: E/AndroidRuntime(13016):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
01-01 22:13:31.862: E/AndroidRuntime(13016):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
01-01 22:13:31.862: E/AndroidRuntime(13016):    ... 11 more
01-01 22:13:31.927: E/AppErrorDialog(494): Failed to get ILowStorageHandle instance
01-01 22:15:50.133: E/AndroidRuntime(13111): FATAL EXCEPTION: main
01-01 22:15:50.133: E/AndroidRuntime(13111): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.vogella.android.locationapi.maps/com.vogella.android.locationapi.maps.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.vogella.android.locationapi.maps.MainActivity" on path: DexPathList[[zip file "/data/app/com.vogella.android.locationapi.maps-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.vogella.android.locationapi.maps-2, /vendor/lib, /system/lib]]
01-01 22:15:50.133: E/AndroidRuntime(13111):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at android.app.ActivityThread.access$600(ActivityThread.java:162)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at android.os.Handler.dispatchMessage(Handler.java:107)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at android.os.Looper.loop(Looper.java:194)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at android.app.ActivityThread.main(ActivityThread.java:5371)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at java.lang.reflect.Method.invokeNative(Native Method)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at java.lang.reflect.Method.invoke(Method.java:525)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at dalvik.system.NativeStart.main(Native Method)
01-01 22:15:50.133: E/AndroidRuntime(13111): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.vogella.android.locationapi.maps.MainActivity" on path: DexPathList[[zip file "/data/app/com.vogella.android.locationapi.maps-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.vogella.android.locationapi.maps-2, /vendor/lib, /system/lib]]
01-01 22:15:50.133: E/AndroidRuntime(13111):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
01-01 22:15:50.133: E/AndroidRuntime(13111):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
01-01 22:15:50.133: E/AndroidRuntime(13111):    ... 11 more
01-01 22:15:50.184: E/AppErrorDialog(494): Failed to get ILowStorageHandle instance
01-01 22:16:50.897: E/PlayEventLogger(11433): Upload failed class java.net.UnknownHostException(Unable to resolve host "play.googleapis.com": No address associated with hostname)
01-01 22:17:17.911: E/CellLocation(861): create GsmCellLocation
01-01 22:17:17.915: E/CellLocation(861): create GsmCellLocation
01-01 22:17:32.905: E/CellLocation(861): create GsmCellLocation
01-01 22:17:32.909: E/CellLocation(861): create GsmCellLocation

1 个答案:

答案 0 :(得分:0)

尝试将其添加为元素的子元素:

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />