百度地图应用出错

Java_Liam 发布于 2013/08/16 21:55
阅读 7K+
收藏 0

在运用百度地图时,失败啦!特贴出求指导!

【1】输出日志如下:

08-16 19:31:27.148: D/dalvikvm(552): Not late-enabling CheckJNI (already on)
08-16 19:31:28.248: I/Tester(552): MapManagerFactory.onCreate()
08-16 19:31:28.248: I/Tester(552): MapManagerFactory.initManager()
08-16 19:31:28.248: D/dalvikvm(552): Trying to load lib /data/data/com.Liam.map_demo/lib/libBaiduMapVOS_v2_1_3.so 0x4176b518
08-16 19:31:28.328: D/dalvikvm(552): Added shared lib /data/data/com.Liam.map_demo/lib/libBaiduMapVOS_v2_1_3.so 0x4176b518
08-16 19:31:28.328: D/dalvikvm(552): No JNI_OnLoad found in /data/data/com.Liam.map_demo/lib/libBaiduMapVOS_v2_1_3.so 0x4176b518, skipping init
08-16 19:31:28.328: D/dalvikvm(552): Trying to load lib /data/data/com.Liam.map_demo/lib/libBaiduMapSDK_v2_1_3.so 0x4176b518
08-16 19:31:28.328: D/dalvikvm(552): Added shared lib /data/data/com.Liam.map_demo/lib/libBaiduMapSDK_v2_1_3.so 0x4176b518
08-16 19:31:28.898: W/System.err(552): java.lang.StringIndexOutOfBoundsException: length=15; regionStart=0; regionLength=-1
08-16 19:31:28.908: W/System.err(552): 	at java.lang.String.startEndAndLength(String.java:593)
08-16 19:31:28.908: W/System.err(552): 	at java.lang.String.substring(String.java:1474)
08-16 19:31:28.908: W/System.err(552): 	at com.baidu.platform.comapi.d.c.j(Unknown Source)
08-16 19:31:28.908: W/System.err(552): 	at com.baidu.platform.comapi.d.c.g(Unknown Source)
08-16 19:31:28.908: W/System.err(552): 	at com.baidu.platform.comapi.d.c.c(Unknown Source)
08-16 19:31:28.908: W/System.err(552): 	at com.baidu.platform.comapi.a.a(Unknown Source)
08-16 19:31:28.908: W/System.err(552): 	at com.baidu.mapapi.BMapManager.init(Unknown Source)
08-16 19:31:28.908: W/System.err(552): 	at com.Liam.map_demo.MapManagerFactory.initManager(MapManagerFactory.java:32)
08-16 19:31:28.908: W/System.err(552): 	at com.Liam.map_demo.MapManagerFactory.onCreate(MapManagerFactory.java:23)
08-16 19:31:28.918: W/System.err(552): 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
08-16 19:31:28.918: W/System.err(552): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3925)
08-16 19:31:28.918: W/System.err(552): 	at android.app.ActivityThread.access$1300(ActivityThread.java:122)
08-16 19:31:28.918: W/System.err(552): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1184)
08-16 19:31:28.918: W/System.err(552): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 19:31:28.918: W/System.err(552): 	at android.os.Looper.loop(Looper.java:137)
08-16 19:31:28.918: W/System.err(552): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-16 19:31:28.918: W/System.err(552): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-16 19:31:28.918: W/System.err(552): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-16 19:31:28.918: W/System.err(552): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-16 19:31:28.918: W/System.err(552): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-16 19:31:28.918: W/System.err(552): 	at dalvik.system.NativeStart.main(Native Method)
08-16 19:31:29.128: W/System.err(552): java.lang.StringIndexOutOfBoundsException: length=15; regionStart=0; regionLength=-1
08-16 19:31:29.128: W/System.err(552): 	at java.lang.String.startEndAndLength(String.java:593)
08-16 19:31:29.128: W/System.err(552): 	at java.lang.String.substring(String.java:1474)
08-16 19:31:29.168: W/System.err(552): 	at com.baidu.platform.comapi.d.c.j(Unknown Source)
08-16 19:31:29.168: W/System.err(552): 	at com.baidu.platform.comapi.d.c.c(Unknown Source)
08-16 19:31:29.168: W/System.err(552): 	at com.baidu.platform.comapi.a.a(Unknown Source)
08-16 19:31:29.168: W/System.err(552): 	at com.baidu.mapapi.BMapManager.init(Unknown Source)
08-16 19:31:29.168: W/System.err(552): 	at com.Liam.map_demo.MapManagerFactory.initManager(MapManagerFactory.java:32)
08-16 19:31:29.168: W/System.err(552): 	at com.Liam.map_demo.MapManagerFactory.onCreate(MapManagerFactory.java:23)
08-16 19:31:29.168: W/System.err(552): 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
08-16 19:31:29.168: W/System.err(552): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3925)
08-16 19:31:29.168: W/System.err(552): 	at android.app.ActivityThread.access$1300(ActivityThread.java:122)
08-16 19:31:29.168: W/System.err(552): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1184)
08-16 19:31:29.168: W/System.err(552): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 19:31:29.168: W/System.err(552): 	at android.os.Looper.loop(Looper.java:137)
08-16 19:31:29.168: W/System.err(552): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-16 19:31:29.168: W/System.err(552): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-16 19:31:29.168: W/System.err(552): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-16 19:31:29.168: W/System.err(552): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-16 19:31:29.168: W/System.err(552): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-16 19:31:29.168: W/System.err(552): 	at dalvik.system.NativeStart.main(Native Method)
08-16 19:31:29.278: W/System.err(552): java.lang.StringIndexOutOfBoundsException: length=15; regionStart=0; regionLength=-1
08-16 19:31:29.278: W/System.err(552): 	at java.lang.String.startEndAndLength(String.java:593)
08-16 19:31:29.278: W/System.err(552): 	at java.lang.String.substring(String.java:1474)
08-16 19:31:29.278: W/System.err(552): 	at com.baidu.platform.comapi.d.c.j(Unknown Source)
08-16 19:31:29.278: W/System.err(552): 	at com.baidu.platform.comapi.d.c.e(Unknown Source)
08-16 19:31:29.278: W/System.err(552): 	at com.baidu.platform.comapi.a.a(Unknown Source)
08-16 19:31:29.278: W/System.err(552): 	at com.baidu.mapapi.BMapManager.init(Unknown Source)
08-16 19:31:29.278: W/System.err(552): 	at com.Liam.map_demo.MapManagerFactory.initManager(MapManagerFactory.java:32)
08-16 19:31:29.310: W/System.err(552): 	at com.Liam.map_demo.MapManagerFactory.onCreate(MapManagerFactory.java:23)
08-16 19:31:29.310: W/System.err(552): 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
08-16 19:31:29.318: W/System.err(552): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3925)
08-16 19:31:29.318: W/System.err(552): 	at android.app.ActivityThread.access$1300(ActivityThread.java:122)
08-16 19:31:29.318: W/System.err(552): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1184)
08-16 19:31:29.318: W/System.err(552): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 19:31:29.318: W/System.err(552): 	at android.os.Looper.loop(Looper.java:137)
08-16 19:31:29.318: W/System.err(552): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-16 19:31:29.318: W/System.err(552): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-16 19:31:29.318: W/System.err(552): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-16 19:31:29.318: W/System.err(552): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-16 19:31:29.329: W/System.err(552): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-16 19:31:29.329: W/System.err(552): 	at dalvik.system.NativeStart.main(Native Method)
08-16 19:31:29.418: W/System.err(552): java.lang.StringIndexOutOfBoundsException: length=15; regionStart=0; regionLength=-1
08-16 19:31:29.418: W/System.err(552): 	at java.lang.String.startEndAndLength(String.java:593)
08-16 19:31:29.458: W/System.err(552): 	at java.lang.String.substring(String.java:1474)
08-16 19:31:29.458: W/System.err(552): 	at com.baidu.platform.comapi.d.c.j(Unknown Source)
08-16 19:31:29.458: W/System.err(552): 	at com.baidu.platform.comapi.d.c.c(Unknown Source)
08-16 19:31:29.458: W/System.err(552): 	at com.baidu.mapapi.utils.PermissionCheck.InitParam(Unknown Source)
08-16 19:31:29.458: W/System.err(552): 	at com.baidu.mapapi.BMapManager.init(Unknown Source)
08-16 19:31:29.458: W/System.err(552): 	at com.Liam.map_demo.MapManagerFactory.initManager(MapManagerFactory.java:32)
08-16 19:31:29.458: W/System.err(552): 	at com.Liam.map_demo.MapManagerFactory.onCreate(MapManagerFactory.java:23)
08-16 19:31:29.458: W/System.err(552): 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
08-16 19:31:29.458: W/System.err(552): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3925)
08-16 19:31:29.468: W/System.err(552): 	at android.app.ActivityThread.access$1300(ActivityThread.java:122)
08-16 19:31:29.468: W/System.err(552): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1184)
08-16 19:31:29.468: W/System.err(552): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 19:31:29.468: W/System.err(552): 	at android.os.Looper.loop(Looper.java:137)
08-16 19:31:29.468: W/System.err(552): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-16 19:31:29.468: W/System.err(552): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-16 19:31:29.478: W/System.err(552): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-16 19:31:29.478: W/System.err(552): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-16 19:31:29.478: W/System.err(552): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-16 19:31:29.478: W/System.err(552): 	at dalvik.system.NativeStart.main(Native Method)
08-16 19:31:29.510: E/dalvikvm(552): JNI ERROR (app bug): accessed stale local reference 0xab300025 (index 9 in a table of size 0)
08-16 19:31:29.510: W/dalvikvm(552): JNI WARNING: jclass is an invalid local reference (0xab300025)
08-16 19:31:29.518: W/dalvikvm(552):              in Ldalvik/system/NativeStart;.run:()V (CallStaticIntMethodV)
08-16 19:31:29.518: I/dalvikvm(552): "Thread-77" prio=5 tid=12 RUNNABLE
08-16 19:31:29.518: I/dalvikvm(552):   | group="main" sCount=0 dsCount=0 obj=0x417a4f20 self=0xc2f30
08-16 19:31:29.518: I/dalvikvm(552):   | sysTid=572 nice=0 sched=0/0 cgrp=default handle=1655808
08-16 19:31:29.518: I/dalvikvm(552):   | schedstat=( 2830905 17866337 8 ) utm=0 stm=0 core=0
08-16 19:31:29.518: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:29.529: E/dalvikvm(552): VM aborting
08-16 19:31:29.529: A/libc(552): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)
08-16 19:31:31.308: W/dalvikvm(552): threadid=5: spin on suspend #1 threadid=12 (pcf=0)
08-16 19:31:32.059: W/dalvikvm(552): threadid=5: spin on suspend #2 threadid=12 (pcf=0)
08-16 19:31:32.082: I/dalvikvm(552): "Compiler" daemon prio=5 tid=5 VMWAIT
08-16 19:31:32.082: I/dalvikvm(552):   | group="system" sCount=0 dsCount=0 obj=0x41764e08 self=0x1d7eb0
08-16 19:31:32.082: I/dalvikvm(552):   | sysTid=560 nice=0 sched=0/0 cgrp=default handle=1241168
08-16 19:31:32.082: I/dalvikvm(552):   | schedstat=( 7147818 81489831 26 ) utm=0 stm=0 core=0
08-16 19:31:32.082: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:32.082: I/dalvikvm(552): "Thread-77" prio=5 tid=12 RUNNABLE
08-16 19:31:32.082: I/dalvikvm(552):   | group="main" sCount=1 dsCount=0 obj=0x417a4f20 self=0xc2f30
08-16 19:31:32.082: I/dalvikvm(552):   | sysTid=572 nice=0 sched=0/0 cgrp=default handle=1655808
08-16 19:31:32.082: I/dalvikvm(552):   | schedstat=( 7657982 27059504 17 ) utm=0 stm=0 core=0
08-16 19:31:32.188: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:32.938: W/dalvikvm(552): threadid=5: spin on suspend #3 threadid=12 (pcf=0)
08-16 19:31:32.938: I/dalvikvm(552): "Compiler" daemon prio=5 tid=5 VMWAIT
08-16 19:31:32.938: I/dalvikvm(552):   | group="system" sCount=0 dsCount=0 obj=0x41764e08 self=0x1d7eb0
08-16 19:31:32.938: I/dalvikvm(552):   | sysTid=560 nice=0 sched=0/0 cgrp=default handle=1241168
08-16 19:31:32.938: I/dalvikvm(552):   | schedstat=( 10902402 188806317 37 ) utm=1 stm=0 core=0
08-16 19:31:32.938: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:32.938: I/dalvikvm(552): "Thread-77" prio=5 tid=12 RUNNABLE
08-16 19:31:32.938: I/dalvikvm(552):   | group="main" sCount=1 dsCount=0 obj=0x417a4f20 self=0xc2f30
08-16 19:31:32.938: I/dalvikvm(552):   | sysTid=572 nice=0 sched=0/0 cgrp=default handle=1655808
08-16 19:31:32.938: I/dalvikvm(552):   | schedstat=( 7657982 27059504 17 ) utm=0 stm=0 core=0
08-16 19:31:32.963: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:33.708: W/dalvikvm(552): threadid=5: spin on suspend #4 threadid=12 (pcf=0)
08-16 19:31:33.708: I/dalvikvm(552): "Compiler" daemon prio=5 tid=5 VMWAIT
08-16 19:31:33.708: I/dalvikvm(552):   | group="system" sCount=0 dsCount=0 obj=0x41764e08 self=0x1d7eb0
08-16 19:31:33.708: I/dalvikvm(552):   | sysTid=560 nice=0 sched=0/0 cgrp=default handle=1241168
08-16 19:31:33.718: I/dalvikvm(552):   | schedstat=( 14908429 211261546 49 ) utm=1 stm=0 core=0
08-16 19:31:33.718: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:33.718: I/dalvikvm(552): "Thread-77" prio=5 tid=12 RUNNABLE
08-16 19:31:33.718: I/dalvikvm(552):   | group="main" sCount=1 dsCount=0 obj=0x417a4f20 self=0xc2f30
08-16 19:31:33.718: I/dalvikvm(552):   | sysTid=572 nice=0 sched=0/0 cgrp=default handle=1655808
08-16 19:31:33.718: I/dalvikvm(552):   | schedstat=( 7657982 27059504 17 ) utm=0 stm=0 core=0
08-16 19:31:33.728: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:34.478: W/dalvikvm(552): threadid=5: spin on suspend #5 threadid=12 (pcf=0)
08-16 19:31:34.478: I/dalvikvm(552): "Compiler" daemon prio=5 tid=5 VMWAIT
08-16 19:31:34.478: I/dalvikvm(552):   | group="system" sCount=0 dsCount=0 obj=0x41764e08 self=0x1d7eb0
08-16 19:31:34.478: I/dalvikvm(552):   | sysTid=560 nice=0 sched=0/0 cgrp=default handle=1241168
08-16 19:31:34.478: I/dalvikvm(552):   | schedstat=( 16865259 232503162 59 ) utm=1 stm=0 core=0
08-16 19:31:34.478: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:34.478: I/dalvikvm(552): "Thread-77" prio=5 tid=12 RUNNABLE
08-16 19:31:34.478: I/dalvikvm(552):   | group="main" sCount=1 dsCount=0 obj=0x417a4f20 self=0xc2f30
08-16 19:31:34.478: I/dalvikvm(552):   | sysTid=572 nice=0 sched=0/0 cgrp=default handle=1655808
08-16 19:31:34.478: I/dalvikvm(552):   | schedstat=( 7657982 27059504 17 ) utm=0 stm=0 core=0
08-16 19:31:34.488: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:35.248: W/dalvikvm(552): threadid=5: spin on suspend #6 threadid=12 (pcf=0)
08-16 19:31:35.248: I/dalvikvm(552): "Compiler" daemon prio=5 tid=5 VMWAIT
08-16 19:31:35.248: I/dalvikvm(552):   | group="system" sCount=0 dsCount=0 obj=0x41764e08 self=0x1d7eb0
08-16 19:31:35.248: I/dalvikvm(552):   | sysTid=560 nice=0 sched=0/0 cgrp=default handle=1241168
08-16 19:31:35.248: I/dalvikvm(552):   | schedstat=( 19647412 244595230 69 ) utm=1 stm=0 core=0
08-16 19:31:35.248: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:35.248: I/dalvikvm(552): "Thread-77" prio=5 tid=12 RUNNABLE
08-16 19:31:35.248: I/dalvikvm(552):   | group="main" sCount=1 dsCount=0 obj=0x417a4f20 self=0xc2f30
08-16 19:31:35.248: I/dalvikvm(552):   | sysTid=572 nice=0 sched=0/0 cgrp=default handle=1655808
08-16 19:31:35.248: I/dalvikvm(552):   | schedstat=( 7657982 27059504 17 ) utm=0 stm=0 core=0
08-16 19:31:35.258: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:36.028: W/dalvikvm(552): threadid=5: spin on suspend #7 threadid=12 (pcf=0)
08-16 19:31:36.028: I/dalvikvm(552): "Compiler" daemon prio=5 tid=5 VMWAIT
08-16 19:31:36.028: I/dalvikvm(552):   | group="system" sCount=0 dsCount=0 obj=0x41764e08 self=0x1d7eb0
08-16 19:31:36.028: I/dalvikvm(552):   | sysTid=560 nice=0 sched=0/0 cgrp=default handle=1241168
08-16 19:31:36.038: I/dalvikvm(552):   | schedstat=( 22443247 296447809 78 ) utm=1 stm=1 core=0
08-16 19:31:36.038: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
08-16 19:31:36.038: I/dalvikvm(552): "Thread-77" prio=5 tid=12 RUNNABLE
08-16 19:31:36.038: I/dalvikvm(552):   | group="main" sCount=1 dsCount=0 obj=0x417a4f20 self=0xc2f30
08-16 19:31:36.038: I/dalvikvm(552):   | sysTid=572 nice=0 sched=0/0 cgrp=default handle=1655808
08-16 19:31:36.038: I/dalvikvm(552):   | schedstat=( 7657982 27059504 17 ) utm=0 stm=0 core=0
08-16 19:31:36.038: I/dalvikvm(552):   at dalvik.system.NativeStart.run(Native Method)
【2】主要代码如下:

【2.1】获取MapManager的Application:

package com.Liam.map_demo;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKGeneralListener;
import com.baidu.mapapi.map.MKEvent;

import android.app.Application;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class MapManagerFactory extends Application {
	public static final String strKey = "8cf07a7389318903085bc5555726b579";
	private static MapManagerFactory mFactory = null;
	BMapManager mapManager = null;
	public boolean m_bKeyRight = true;

	@Override
	public void onCreate() {
		super.onCreate();
		Log.i("Tester", "MapManagerFactory.onCreate()");
		mFactory = this;
		initManager(this);
	}
	
	public void initManager(Context context) {
		Log.i("Tester", "MapManagerFactory.initManager()");
		if (mapManager == null) {
			mapManager = new BMapManager(context);
		}
		
		if (!mapManager.init(strKey, new MInternetListener())) {
			Toast.makeText(MapManagerFactory.getInstance().getApplicationContext(), "MapManagerFactory" +
					"初始化失败!",
                    Toast.LENGTH_LONG).show();
		}
	}
	
	public BMapManager getMapManager() {
		return mapManager;
	}

	public static MapManagerFactory getInstance() {
		return mFactory;
	}

	static class MInternetListener implements MKGeneralListener {

		@Override
        public void onGetNetworkState(int iError) {
			Log.i("Tester", "MapManagerFactory.MKGeneralListener.onGetNetworkState()");
            if (iError == MKEvent.ERROR_NETWORK_CONNECT) {
                Toast.makeText(MapManagerFactory.getInstance().getApplicationContext(), "您的网络出错啦!",
                    Toast.LENGTH_LONG).show();
            }
            else if (iError == MKEvent.ERROR_NETWORK_DATA) {
                Toast.makeText(MapManagerFactory.getInstance().getApplicationContext(), "输入正确的检索条件!",
                        Toast.LENGTH_LONG).show();
            }
        }

		 @Override
	        public void onGetPermissionState(int iError) {
	            if (iError ==  MKEvent.ERROR_PERMISSION_DENIED) {
	                //授权Key错误:
	                Toast.makeText(MapManagerFactory.getInstance().getApplicationContext(), 
	                        "请在 DemoApplication.java文件输入正确的授权Key!", Toast.LENGTH_LONG).show();
	                MapManagerFactory.getInstance().m_bKeyRight = false;
	            }
	        }
		
	}
	
}
【2.2】主题Activity:

package com.Liam.map_demo;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.MapController;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.search.MKAddrInfo;
import com.baidu.mapapi.search.MKBusLineResult;
import com.baidu.mapapi.search.MKDrivingRouteResult;
import com.baidu.mapapi.search.MKPoiResult;
import com.baidu.mapapi.search.MKSearch;
import com.baidu.mapapi.search.MKSearchListener;
import com.baidu.mapapi.search.MKShareUrlResult;
import com.baidu.mapapi.search.MKSuggestionResult;
import com.baidu.mapapi.search.MKTransitRouteResult;
import com.baidu.mapapi.search.MKWalkingRouteResult;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MapActivity extends Activity {
	private MapView map;
	private MapController mController;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MapManagerFactory factory = (MapManagerFactory) this.getApplication();
		if (factory == null) {
			Log.i("Tester", "factory == null");
		}
		if (factory.mapManager == null) {
			Log.i("Tester", "factory.mapManager == null");

			factory.mapManager = new BMapManager(this);

			factory.mapManager.init(MapManagerFactory.strKey,
					new MapManagerFactory.MInternetListener());
		}
		setContentView(R.layout.activity_map);
		map = (MapView) findViewById(R.id.map);
		mController = map.getController();
		mController.enableClick(true);
		mController.setZoom(12);
		map.setBuiltInZoomControls(true);
		MKSearch search = new MKSearch();
		search.geocode("重庆邮电大学", "重庆");
		search.init(factory.mapManager, new MKSearchListener() {
			@Override
			public void onGetWalkingRouteResult(MKWalkingRouteResult arg0, int arg1) {}
			@Override
			public void onGetTransitRouteResult(MKTransitRouteResult arg0, int arg1) {}
			@Override
			public void onGetSuggestionResult(MKSuggestionResult arg0, int arg1) {}
			@Override
			public void onGetShareUrlResult(MKShareUrlResult arg0, int arg1, int arg2) {}
			@Override
			public void onGetPoiResult(MKPoiResult arg0, int arg1, int arg2) {}
			@Override
			public void onGetPoiDetailSearchResult(int arg0, int arg1) {}
			@Override
			public void onGetDrivingRouteResult(MKDrivingRouteResult arg0, int arg1) {}
			@Override
			public void onGetBusDetailResult(MKBusLineResult result, int flag) {}
			@Override
			public void onGetAddrResult(MKAddrInfo result, int arg1) {
				mController.setCenter(result.geoPt);
			}
		});
	}
	
	@Override
	protected void onDestroy() {
		map.destroy();
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		map.onPause();
		super.onPause();
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
		map.onSaveInstanceState(savedInstanceState);
	}

	@Override
	protected void onResume() {
		map.onResume();
		super.onResume();
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		map.onSaveInstanceState(outState);
	}



	public void show(String str) {
		Toast.makeText(MapActivity.this, str, Toast.LENGTH_LONG).show();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(0, 1, 0, "退出");
		getMenuInflater().inflate(R.menu.map, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case 1: {
			new AlertDialog.Builder(MapActivity.this)
					.setTitle("提示")
					.setMessage("是否确认退出程序?")
					.setCancelable(false)
					.setPositiveButton("确定",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									MapActivity.this.finish();
								}
							})
					.setNegativeButton("取消",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									dialog.cancel();
								}
							}).show();
			break;
		}
		}
		return super.onOptionsItemSelected(item);
	}
}
【2.3】layout界面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=".MapActivity" >

    <com.baidu.mapapi.map.MapView 
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true" />

</RelativeLayout>
【2.4】AndroidManifest.xml

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

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

    <permission android:name="android.permission.BAIDU_LOCATION_SERVICE" >
    </permission>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.BAIDU_LOCATION_SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="false"
        android:resizeable="true"
        android:smallScreens="true" />

    <application
        android:name="com.Liam.map_demo.MapManagerFactory"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.Liam.map_demo.MapActivity"
            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>
另附百度地图密钥

项目结构截图:

就这样了,,,就解释,,,为什么失败啦!




加载中
0
改个昵称
改个昵称

亲,你问题解决了吗?


Java_Liam
Java_Liam
么有。。。
0
哇咔咔咔
哇咔咔咔
亲,你问题解决了吗? +2
0
cloor
cloor
JNI没有加载成功
0
张达军

这个问题我也碰到了  求高手

附上参考资料:http://blog.k-res.net/archives/1525.html

 

Java_Liam
Java_Liam
谢谢!
0
黄小敏-搜杂网
黄小敏-搜杂网
07     <uses-sdk
08         android:minSdkVersion="10"
09         android:targetSdkVersion="14" />

这里改为


07     <uses-sdk
08         android:minSdkVersion="7"/>
就可以了
当空皓月
当空皓月
厉害呀!
0
ETmanwenhan
ETmanwenhan

JNI ERROR (app bug): accessed stale local reference 0x94600025 (index 9 in a

楼上说得对!我用的是安卓4.0版本的,我也碰到同样的问题 。

07     <uses-sdk
08         android:minSdkVersion="8"
09         android:targetSdkVersion="14" />

这里改为


    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="10" />
问题就解决了!


0
当空皓月
当空皓月
经测试这个给版本号无关!
0
k
kinglo
http://5geek.cn/post/29419b_c70bf1
返回顶部
顶部