{"id":1418,"date":"2022-08-30T15:16:22","date_gmt":"2022-08-30T15:16:22","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/16\/android-map-version-2-issue-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:22","modified_gmt":"2022-08-30T15:16:22","slug":"android-map-version-2-issue-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/android-map-version-2-issue-collection-of-common-programming-errors\/","title":{"rendered":"Android Map version 2 issue-Collection of common programming errors"},"content":{"rendered":"<p>I am new in android.I create an application for MAP and i install vending.apk and gms.apk in emulator for running map in emulator. And also copy google-play-service_lib project in my eclipse and include google-play-service.zip in my project lib folder and include google-play-service.jar in project.In the time of running it shows error. Logcat is given below. Please help me to solve this problem.<\/p>\n<pre><code>public class MainActivity extends Activity{\n\n            GMapV2GetRouteDirection  routedirection;\n            GoogleMap googlemap;\n            MarkerOptions markerOption;\n            LatLng PositionFrom;\n            LatLng PositionTo;\n            Document document;\n             MarkerOptions markerOptions;\n             Location location ;\n            \/*static final LatLng Poprad = new LatLng(49.055, 20.299);  \n            static final LatLng Prag = new LatLng(50.085, 14.458);*\/\n            private GoogleMap map;\n            @SuppressLint(\"NewApi\")\n            @Override\n            protected void onCreate(Bundle savedInstanceState) {\n                super.onCreate(savedInstanceState);\n                \/\/setContentView(R.layout.activity_main);\n                routedirection=new GMapV2GetRouteDirection();\n                \/*SupportMapFragment mapfragment=(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);\n                googlemap=mapfragment.getMap();*\/\n                map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();\n\n                googlemap.setMyLocationEnabled(true);\n                googlemap.getUiSettings().setZoomControlsEnabled(true);\n                googlemap.getUiSettings().setCompassEnabled(true);\n                googlemap.getUiSettings().setMyLocationButtonEnabled(true);\n                googlemap.getUiSettings().setAllGesturesEnabled(true);\n                googlemap.setTrafficEnabled(true);\n                googlemap.animateCamera(CameraUpdateFactory.zoomTo(10));\n                markerOption=new MarkerOptions();\n                PositionFrom=new LatLng(6777.7,8888.5);\n                PositionTo=new LatLng(4444.3, 3333.4);\n                GetRoutTask getRoute =new GetRoutTask();\n                getRoute.execute();\n            }\n\n            private class GetRoutTask extends AsyncTask{\n\n                private ProgressDialog pdialog;\n                String response = \"\";\n\n                protected void onPreExecute(){\n                    pdialog=new ProgressDialog(MainActivity.this);\n                    pdialog.setMessage(\"Loading.....\");\n                    pdialog.show();\n                }\n\n\n\n                @Override\n                protected String doInBackground(String... params) {\n                    \/\/ TODO Auto-generated method stub\n\n                document=routedirection.Getdocument(PositionFrom, PositionTo, GMapV2GetRouteDirection.MODE_DRIVING);\n                response = \"Success\";\n                return response;\n                }\n\n                  protected void onPostExecute(String result) {\n                      googlemap.clear();\n                      if(response.equalsIgnoreCase(\"Success\")){\n                      ArrayList directionPoint = routedirection.getDirection(document);\n                      PolylineOptions rectLine = new PolylineOptions().width(10).color(\n                                  Color.RED);\n\n                      for (int i = 0; i &lt; directionPoint.size(); i++) {\n                            rectLine.add(directionPoint.get(i));\n                      }\n                      \/\/ Adding route on the map\n                      googlemap.addPolyline(rectLine);\n                      markerOptions.position(PositionFrom);\n                      markerOptions.draggable(true);\n                      googlemap.addMarker(markerOptions);\n\n                      }\n\n                      pdialog.dismiss();\n                }\n\n\n\n            }\n\n\n            @Override\n            public boolean onCreateOptionsMenu(Menu menu) {\n                \/\/ Inflate the menu; this adds items to the action bar if it is present.\n                getMenuInflater().inflate(R.menu.main, menu);\n                return true;\n            }\n\n        }\n<\/code><\/pre>\n<p>Manifest<\/p>\n<pre><code>    \n    \n\n        \n\n        \n        \n\n            \n            \n            \n            \n            \n            \n        \n            \n                \n                    \n\n                    \n                \n            \n             \n        \n\n    \n<\/code><\/pre>\n<p>LOGCAT<\/p>\n<pre><code>07-26 14:24:22.261: W\/dalvikvm(860): threadid=1: thread exiting with uncaught exception (group=0x40a13300)\n07-26 14:24:22.291: E\/AndroidRuntime(860): FATAL EXCEPTION: main\n07-26 14:24:22.291: E\/AndroidRuntime(860): java.lang.RuntimeException: Unable to start activity ComponentInfo{example.map\/example.map.MainActivity}: java.lang.NullPointerException\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at android.app.ActivityThread.access$600(ActivityThread.java:130)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at android.os.Handler.dispatchMessage(Handler.java:99)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at android.os.Looper.loop(Looper.java:137)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at android.app.ActivityThread.main(ActivityThread.java:4745)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at java.lang.reflect.Method.invokeNative(Native Method)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at java.lang.reflect.Method.invoke(Method.java:511)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at dalvik.system.NativeStart.main(Native Method)\n07-26 14:24:22.291: E\/AndroidRuntime(860): Caused by: java.lang.NullPointerException\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at example.map.MainActivity.onCreate(MainActivity.java:49)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at android.app.Activity.performCreate(Activity.java:5008)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)\n07-26 14:24:22.291: E\/AndroidRuntime(860):  ... 11 more\n07-26 14:25:04.591: I\/Process(860): Sending signal. PID: 860 SIG: 9\n<\/code><\/pre>\n<ol>\n<li>\n<p>You need to reference the google play services library project in your map project.<\/p>\n<p>Copy the google-play services_lib library project to your workspace (folder where your android map project is). The library project can be found under the following path.<\/p>\n<pre><code>     \/extras\/google\/google_play_services\/libproject\/google-play-services_lib library project .\n<\/code><\/pre>\n<p>Import the library project to your eclipse<\/p>\n<p><strong>Click File &gt; Import, select Android &gt; Existing Android Code into Workspace, and browse the workspace import the library project<\/strong>. You can check if it is library project. Right click on the library project. Goto properties. Click Android on the left panel. You will see Is Library checked.<\/p>\n<p>Right click on your android project. Goto properties. Choose Android on the left panel. Click on Add and browse the library project. Select the same. Click ok and apply<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/6LSbz.png\" \/><\/p>\n<p>Edit:<\/p>\n<p>Your min sdk is 8 So you should use <code>SupportMapFragment<\/code>.<\/p>\n<pre><code>\n<\/code><\/pre>\n<p>Your activity must extend <code>FragmentActivity<\/code>.<\/p>\n<pre><code>SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);\nGoogleMap mMap = fm.getMap(); \n<\/code><\/pre>\n<p>Also make sure you imported the below<\/p>\n<pre><code>import android.support.v4.app.FragmentActivity;  \nimport com.google.android.gms.maps.SupportMapFragment;  \n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-16 20:49:32. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am new in android.I create an application for MAP and i install vending.apk and gms.apk in emulator for running map in emulator. And also copy google-play-service_lib project in my eclipse and include google-play-service.zip in my project lib folder and include google-play-service.jar in project.In the time of running it shows error. Logcat is given below. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1418","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1418"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1418\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}