2014-12-05 73 views
0

我想用Google Maps API v2構建應用程序,但事情是,應用程序一直給我提供錯誤,遺憾的是.apk已停止工作,儘管我遵循所有必需的說明。請查看我的代碼並幫助我找出問題所在。由於提前構建谷歌地圖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 
+0

檢查,並與我們分享您的logcat,以確定我的代碼 – MTahir 2014-12-05 18:42:02

+0

塔希爾·巴伊請提問題,你有沒有使用'logcat'? – 2014-12-05 18:50:08

+0

真正的罪魁禍首:) – MTahir 2014-12-05 18:51:30

回答

0

嘗試將以此爲元​​素的子:

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