Runtime Exception unable to start MainActivity

一世执手 提交于 2019-12-06 08:02:28
NullPointerException

I think your

 Location myLocation = locationManager.getLastKnownLocation(provider); 

line returning null.

Please check this answer. It might be helpful

M D

Here, If you are targeting your minimum SDK version < 12 in your manifest file then you can't use MapFragment. So must be sure that your minimum SDK version is above or equals to 12. And if it is not then change in your xml file from

android:name="com.google.android.gms.maps.MapFragment"

to

android:name="com.google.android.gms.maps.SupportMapFragment"

And also in your activity change from

 map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

to

 map=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

And also If you're using fragments on older devices (pre Honeycomb) you should always extend your Activity from FragmentActivity.

Also import android.support.v4.app.FragmentActivity and for more information on this go to my this answer

If I don't mistake, fragments should be used in Activity which extends either Fragment or FragmentActivity. Probably something is wrong with map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!