1

I am simply trying to load the Maps application in my app but it always get closed with a message, Unfortunately, the app has stopped.

I have searched other stackoverflow answers as well, but not getting it that why this is getting forced close every time I clicked the Show Map button.

My code is:

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

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

Himanshu Aggarwal
  • 1,803
  • 2
  • 24
  • 36

2 Answers2

2

First, the geo: URL you are trying to parse is not one of the documented and supported structures, above and beyond the invalid < and > noted in cygery's answer.

Second, your device or emulator may not have a map application on it that honors geo: Intents.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I even tried, `i.setData(Uri.parse("geo:47.6,-122.3"));` but the same problem persists. I read somewhere that the AVD must support the Google API. I installed the same for the API 19 (I am using). Then how to rectify this problem? – Himanshu Aggarwal Aug 09 '14 at 19:23
  • @HimanshuAggarwal: Just because you installed something does not mean that your AVD is using it. Make sure your AVD has "Google APIs" in the "Target Name" column in the AVD Manager. – CommonsWare Aug 09 '14 at 19:25
  • I implemented the same as you said, but my Maps app is only showing a black screen with a search at the top. What should I do now? – Himanshu Aggarwal Aug 09 '14 at 19:50
  • @HimanshuAggarwal: Try running the Maps app directly from the home screen launcher. If you get the same result, then the problem is with the emulator, Google Maps, or your network (e.g., a firewall), and not your app. – CommonsWare Aug 09 '14 at 19:55
  • I tried that too earlier. Same thing persists. Don't know what to do to rectify this problem now. :( – Himanshu Aggarwal Aug 09 '14 at 19:58
  • @HimanshuAggarwal: The problem is not with your app. I rarely use an emulator for working with Google Maps, so I do not have any particular advice on trying to get that to work better for you. – CommonsWare Aug 09 '14 at 20:00
  • It's working perfectly in my device. But, if anyone knows how to rectify this problem, do comment on it further. – Himanshu Aggarwal Aug 09 '14 at 20:11
1

Remove the < and > in the URI:

i.setData(Uri.parse("geo:28.629404,77.086824?q=28.629404,77.086824"));
cygery
  • 2,309
  • 3
  • 18
  • 25