我只是想在我的应用中加载Google地图应用,但它总是会收到一条消息,Unfortunately, the app has stopped.
我也搜索了其他stackoverflow的答案,但没有得到它为什么每次点击Show Map
按钮时强行关闭的原因。
我的代码是:
<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.himanshu.intents.MainActivity" >
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:layout_marginTop="14dp"
android:onClick="onClickSM"
android:text="Show Map" />
</RelativeLayout>
MainActivity文件:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClickSM(View v) {
Intent i = new Intent (android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("geo:<28.629404>,<77.086824>?q=<28.629404>,<77.086824>"));
startActivity(i);
}
}
LogCat Messsages:
08-09 14:31:58.142: D/dalvikvm(2001): Not late-enabling CheckJNI (already on)
08-09 14:31:58.372: D/(2001): HostConnection::get() New Host Connection established 0xb7f424f0, tid 2001
08-09 14:31:58.422: W/EGL_emulation(2001): eglSurfaceAttrib not implemented
08-09 14:31:58.432: D/OpenGLRenderer(2001): Enabling debug mode 0
08-09 14:32:02.632: D/AndroidRuntime(2001): Shutting down VM
08-09 14:32:02.632: W/dalvikvm(2001): threadid=1: thread exiting with uncaught exception (group=0xb2d72b20)
08-09 14:32:02.632: E/AndroidRuntime(2001): FATAL EXCEPTION: main
08-09 14:32:02.632: E/AndroidRuntime(2001): Process: com.himanshu.intents, PID: 2001
08-09 14:32:02.632: E/AndroidRuntime(2001): java.lang.IllegalStateException: Could not execute method of the activity
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.view.View$1.onClick(View.java:3823)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.view.View.performClick(View.java:4438)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.view.View$PerformClick.run(View.java:18422)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.os.Handler.handleCallback(Handler.java:733)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.os.Handler.dispatchMessage(Handler.java:95)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.os.Looper.loop(Looper.java:136)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.ActivityThread.main(ActivityThread.java:5017)
08-09 14:32:02.632: E/AndroidRuntime(2001): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 14:32:02.632: E/AndroidRuntime(2001): at java.lang.reflect.Method.invoke(Method.java:515)
08-09 14:32:02.632: E/AndroidRuntime(2001): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-09 14:32:02.632: E/AndroidRuntime(2001): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-09 14:32:02.632: E/AndroidRuntime(2001): at dalvik.system.NativeStart.main(Native Method)
08-09 14:32:02.632: E/AndroidRuntime(2001): Caused by: java.lang.reflect.InvocationTargetException
08-09 14:32:02.632: E/AndroidRuntime(2001): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 14:32:02.632: E/AndroidRuntime(2001): at java.lang.reflect.Method.invoke(Method.java:515)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.view.View$1.onClick(View.java:3818)
08-09 14:32:02.632: E/AndroidRuntime(2001): ... 11 more
08-09 14:32:02.632: E/AndroidRuntime(2001): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=geo:<28.629404>,<77.086824>?q=<28.629404>,<77.086824> }
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Activity.startActivityForResult(Activity.java:3424)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Activity.startActivityForResult(Activity.java:3385)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Activity.startActivity(Activity.java:3627)
08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Activity.startActivity(Activity.java:3595)
08-09 14:32:02.632: E/AndroidRuntime(2001): at com.himanshu.intents.MainActivity.onClickSM(MainActivity.java:32)
08-09 14:32:02.632: E/AndroidRuntime(2001): ... 14 more
答案 0 :(得分:2)
首先,您尝试解析的geo:
网址不是the documented and supported structures之一,超出了在cygery&s;中注明的无效<
和>
之内答案。
其次,您的设备或模拟器上可能没有符合geo:
Intent
的地图应用程序。
答案 1 :(得分:1)
删除URI中的<
和>
:
i.setData(Uri.parse("geo:28.629404,77.086824?q=28.629404,77.086824"));