我正在开发一个使用 goolge 地图的 Android 项目。但是当我尝试在平板电脑或 HTC 手机上运行它时,它说应用程序已意外停止。我需要做什么样的设置,比如添加库文件等等。
我也使用了我的 API 密钥,所以如果这个应用程序在设备上运行,我可以查看地图还是只查看网格?签署应用程序是什么意思?
MainActivity.java
package com.sulav.maptravis2;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends MapActivity {
MapView map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try{
map=(MapView) findViewById(R.id.mvMain);
map.setBuiltInZoomControls(true);
}
catch(Exception e){}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
activity_main.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"
tools:context=".MainActivity" >
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mvMain"
android:apiKey="AIzaSyBxPKfOUpiOK981HFNcXi6szt0Dn__tQko"
/>
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sulav.maptravis2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<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="com.sulav.maptravis2.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>
</application>
</manifest>
日志输出:
05-24 12:06:46.285: I/dalvikvm(7686): Could not find method android.security.MessageDigest.getInstance, referenced from method com.google.android.maps.KeyHelper.getSignatureFingerprint
05-24 12:06:46.285: W/dalvikvm(7686): VFY: unable to resolve static method 153: Landroid/security/MessageDigest;.getInstance (Ljava/lang/String;)Landroid/security/MessageDigest;
05-24 12:06:46.285: D/dalvikvm(7686): VFY: replacing opcode 0x71 at 0x0038
05-24 12:06:46.295: D/AndroidRuntime(7686): Shutting down VM
05-24 12:06:46.295: W/dalvikvm(7686): threadid=1: thread exiting with uncaught exception (group=0x409fe1f8)
05-24 12:06:46.305: E/AndroidRuntime(7686): FATAL EXCEPTION: main
05-24 12:06:46.305: E/AndroidRuntime(7686): java.lang.NoClassDefFoundError: android.security.MessageDigest
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.google.android.maps.KeyHelper.getSignatureFingerprint(KeyHelper.java:60)
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.google.android.maps.MapActivity.createMap(MapActivity.java:552)
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.google.android.maps.MapActivity.onCreate(MapActivity.java:422)
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.sulav.maptravis2.MainActivity.onCreate(MainActivity.java:13)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.Activity.performCreate(Activity.java:4465)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.os.Handler.dispatchMessage(Handler.java:99)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.os.Looper.loop(Looper.java:137)
05-24 12:06:46.305: E/AndroidRuntime(7686): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-24 12:06:46.305: E/AndroidRuntime(7686): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 12:06:46.305: E/AndroidRuntime(7686): at java.lang.reflect.Method.invoke(Method.java:511)
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-24 12:06:46.305: E/AndroidRuntime(7686): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-24 12:06:46.305: E/AndroidRuntime(7686): at dalvik.system.NativeStart.main(Native Method)