Android app using google maps not working on phone - android

I'm developing an application which uses a map. I use my galaxy nexus to test the app but after I included the code related to the map it stopped working on my phone but it still works on the emulator. The problem is that the emulator doesnt show the map because it doesnt have Google Play Services.
When I try to launch the app I get no error but my phone does nothing, and if I try to run it manually from the app drawer the app is there but it says "isn't installed".
Here is the java code MainActivity.java
package myPackage.android;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import com.actionbarsherlock.view.*;
public class MainActivity extends SherlockFragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//private GoogleMap map;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getSupportMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.action_search:
final int RESULT=1;
startActivityForResult(new Intent(MainActivity.this, SearchForm.class), RESULT);
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here's the xml layout activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
and the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package=myPackage.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<permission
android:name="myPackage.android.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="myPackage.android.permission.MAPS_RECEIVE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light.DarkActionBar" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my ap map key"/>
<activity
android:name="myPackage.android.SplashScreen"
android:label="#string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:permission="android.permission.INTERNET" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="myPackage.android.MainActivity"
android:label=""
android:logo="#drawable/logo"
android:screenOrientation="portrait"
android:permission="android.permission.INTERNET" >
</activity>
<activity
android:name="myPackage.android.SearchForm"
android:label="#string/title_activity_search_form"
android:parentActivityName="ar.com.package.android.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="myPackage.android.MainActivity" />
</activity>
</application>
</manifest>
logCat
05-09 21:17:04.744: D/AndroidRuntime(15507): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
05-09 21:17:04.744: D/AndroidRuntime(15507): CheckJNI is OFF
05-09 21:17:04.752: D/dalvikvm(15507): Trying to load lib libjavacore.so 0x0
05-09 21:17:04.760: D/dalvikvm(15507): Added shared lib libjavacore.so 0x0
05-09 21:17:04.768: D/dalvikvm(15507): Trying to load lib libnativehelper.so 0x0
05-09 21:17:04.768: D/dalvikvm(15507): Added shared lib libnativehelper.so 0x0
05-09 21:17:04.908: D/AndroidRuntime(15507): Calling main entry com.android.commands.pm.Pm
05-09 21:17:04.916: D/AndroidRuntime(15507): Shutting down VM
05-09 21:17:04.916: D/dalvikvm(15507): GC_CONCURRENT freed 97K, 18% free 482K/584K, paused 1ms+0ms, total 4ms
05-09 21:17:04.924: D/jdwp(15507): Got wake-up signal, bailing out of select
05-09 21:17:04.924: D/dalvikvm(15507): Debugger has detached; object registry had 1 entries
05-09 21:17:05.314: D/AndroidRuntime(15519): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
05-09 21:17:05.314: D/AndroidRuntime(15519): CheckJNI is OFF
05-09 21:17:05.330: D/dalvikvm(15519): Trying to load lib libjavacore.so 0x0
05-09 21:17:05.330: D/dalvikvm(15519): Added shared lib libjavacore.so 0x0
05-09 21:17:05.338: D/dalvikvm(15519): Trying to load lib libnativehelper.so 0x0
05-09 21:17:05.338: D/dalvikvm(15519): Added shared lib libnativehelper.so 0x0
05-09 21:17:05.486: D/AndroidRuntime(15519): Calling main entry com.android.commands.am.Am
05-09 21:17:05.494: D/dalvikvm(15519): Note: class Landroid/app/ActivityManagerNative; has 157 unimplemented (abstract) methods
05-09 21:17:05.502: I/ActivityManager(407): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=myPackage.android/.SplashScreen} from pid 15519
05-09 21:17:05.502: I/AndroidRuntime(15519): VM exiting with result code 1.
05-09 21:17:05.502: W/ActivityManager(407): Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=myPackage.android/.SplashScreen } from null (pid=15519, uid=2000) requires android.permission.INTERNET

Well, I figured it out; i didnt have to use the android:permission atribute under the activities in the manifest. After deleting that the app works just fine.

You can try this code.
public class MainActivity extends FragmentActivity {
// for google map
private GoogleMap mMap;
SupportMapFragment mapFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMap = mapFragment.getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.getUiSettings().setCompassEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
}
If you getting any problem then let me know.

Related

Getting long and lat returns a nullpointexception in android map v2

I tried following the tutorial from Google here. I believe I followed every instruction written but I still get nullpointexception when I try to get my long and lat coordinates.
It works fine if I press the target icon in the map that redirects me to my current location. But when I try it programmatically, it returns nullpointexception. I tried looking in stackoverflow for similar situations like mine but so far none of them works.
If you can provide me with a sample working source file or code that I can test myself it is much appreciated. Below are my source code in case I missed something. Thanks in advance.
manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sample.map.activity"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="false"
android:xlargeScreens="true" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="sample.map.activity"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAdqod8BHch40COYn19c6Ds0uhyfkX25SA" />
</application>
</manifest>
map activity class
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
public class MapActivity extends ActionBarActivity {
GoogleMap map;
Location location;
LatLng myLocation;
LocationManager lm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = lm.getBestProvider(criteria, true);
map = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
map.setMyLocationEnabled(true);
location = lm.getLastKnownLocation(provider);
double mLat = location.getLatitude();
double mLong = location.getLongitude();
Toast.makeText(getApplicationContext(), mLat+" "+mLong, Toast.LENGTH_LONG).show();
map.animateCamera(CameraUpdateFactory.newLatLngZoom(myLocation, 13));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.map, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is the stack trace
05-18 22:45:44.043: E/AndroidRuntime(1220): FATAL EXCEPTION: main
05-18 22:45:44.043: E/AndroidRuntime(1220): Process: sample.map.activity, PID: 1220
05-18 22:45:44.043: E/AndroidRuntime(1220): java.lang.RuntimeException: Unable to start activity ComponentInfo{sample.map.activity/sample.map.activity.MapActivity}: java.lang.NullPointerException
05-18 22:45:44.043: E/AndroidRuntime(1220): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-18 22:45:44.043: E/AndroidRuntime(1220): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-18 22:45:44.043: E/AndroidRuntime(1220): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-18 22:45:44.043: E/AndroidRuntime(1220): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-18 22:45:44.043: E/AndroidRuntime(1220): at android.os.Handler.dispatchMessage(Handler.java:102)
05-18 22:45:44.043: E/AndroidRuntime(1220): at android.os.Looper.loop(Looper.java:136)
05-18 22:45:44.043: E/AndroidRuntime(1220): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-18 22:45:44.043: E/AndroidRuntime(1220): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 22:45:44.043: E/AndroidRuntime(1220): at java.lang.reflect.Method.invoke(Method.java:515)
05-18 22:45:44.043: E/AndroidRuntime(1220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-18 22:45:44.043: E/AndroidRuntime(1220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-18 22:45:44.043: E/AndroidRuntime(1220): at dalvik.system.NativeStart.main(Native Method)
05-18 22:45:44.043: E/AndroidRuntime(1220): Caused by: java.lang.NullPointerException
05-18 22:45:44.043: E/AndroidRuntime(1220): at sample.map.activity.MapActivity.onCreate(MapActivity.java:39)
05-18 22:45:44.043: E/AndroidRuntime(1220): at android.app.Activity.performCreate(Activity.java:5231)
05-18 22:45:44.043: E/AndroidRuntime(1220): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-18 22:45:44.043: E/AndroidRuntime(1220): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-18 23:04:59.383: W/ActivityThread(1354): ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());
05-18 23:04:59.813: I/Process(1354): Sending signal. PID: 1354 SIG: 9
05-18 23:05:01.123: D/dalvikvm(1401): GC_FOR_ALLOC freed 89K, 6% free 2960K/3128K, paused 26ms, total 28ms
05-18 23:05:01.123: I/dalvikvm-heap(1401): Grow heap (frag case) to 3.569MB for 635812-byte allocation
05-18 23:05:01.163: D/dalvikvm(1401): GC_FOR_ALLOC freed 2K, 5% free 3578K/3752K, paused 32ms, total 32ms
05-18 23:05:01.253: W/Visite Dates(1401): Reselected 0 tab name Unposted
05-18 23:05:01.463: D/(1401): HostConnection::get() New Host Connection established 0xb82b7f80, tid 1401
05-18 23:05:01.513: W/EGL_emulation(1401): eglSurfaceAttrib not implemented
05-18 23:05:01.523: D/OpenGLRenderer(1401): Enabling debug mode 0
05-18 23:51:25.343: W/EGL_emulation(1401): eglSurfaceAttrib not implemented
05-18 23:54:27.943: W/EGL_emulation(1401): eglSurfaceAttrib not implemented
Here is the xml file of my layout.
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
I dont know what you have done in your xml file,but your xml file must look like this:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Also Add the following,
< meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" >
< /meta-data>
in your manifest file immediately below the first meta-data tag(where you have placed your google api key).
Also I havent used the camera code that you have written to animate camera.My code:
CameraPosition cameraPosition = new CameraPosition.Builder().target(
new LatLng(your_lat, your_long)).zoom(12).build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Finally got it to work. It seems that the problem is the network provider.
Instead of using Criteria and getBestProvider I followed this approach. What it does is loop to a list of network provider and returns the best existing provider in your mobile phone manually.

Android Google MapV2 doesn't work on intellijIdea

This is my main class
package com.example.mapv2example;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MyActivity extends FragmentActivity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Android Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapv2example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<permission
android:name="com.example.mapv2example.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.example.mapv2example.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name="com.example.mapv2example.MyActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY_API_Key" />
</application>
</manifest>
and the main.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=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
I am works on IntellijIdea 12 and I add android support library and google play services but when I try to run my app emulator "unfortunately,mapv2example has stopped" I get map version 2 api key from google also this is my error log
12-26 09:03:12.852: ERROR/AndroidRuntime(1714): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapv2example/com.example.mapv2example.MyActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.mapv2example.MyActivity.onCreate(MyActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
... 11 more
12-26 09:03:12.996: WARN/ActivityManager(298): Force finishing activity com.example.mapv2example/.MyActivity
12-26 09:03:13.043: WARN/WindowManager(298): Screenshot failure taking screenshot for (328x583) to layer 22010
12-26 09:03:13.652: WARN/ActivityManager(298): Activity pause timeout for ActivityRecord{41896338 u0 com.example.mapv2example/.MyActivity}
12-26 09:03:24.261: WARN/ActivityManager(298): Activity destroy timeout for ActivityRecord{41896338 u0 com.example.mapv2example/.MyActivity}
12-26 09:08:13.061: INFO/Process(1714): Sending signal. PID: 1714 SIG: 9
12-26 09:08:13.071: INFO/ActivityManager(298): Process com.example.mapv2example (pid 1714) has died.
12-26 09:08:13.111: WARN/InputMethodManagerService(298): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#41c4dd88 attribute=null, token = android.os.BinderProxy#41b7fd80
12-26 09:10:33.132: DEBUG/dalvikvm(435): GC_FOR_ALLOC freed 511K, 19% free 3041K/3752K, paused 540ms, total 540ms
12-26 09:20:33.401: INFO/ActivityManager(298): No longer want com.android.exchange (pid 1420): empty for 1804s
12-26 09:21:33.782: INFO/ActivityManager(298): No longer want com.android.browser (pid 1511): empty for 1810s
12-26 09:21:33.844: INFO/ActivityManager(298): No longer want com.android.calendar (pid 1495): empty for 1811s
12-26 09:21:33.897: INFO/ActivityManager(298): No longer want com.android.sharedstoragebackup (pid 1531): empty for 1809s
12-26 09:21:41.868: DEBUG/GCM(490): Ignoring attempt to send heartbeat on dead connection.
12-26 09:23:08.892: DEBUG/dalvikvm(298): GC_FOR_ALLOC freed 1142K, 38% free 7504K/12064K, paused 113ms, total 128ms
12-26 09:26:45.921: INFO/EventLogService(490): Aggregate from 1388066205680 (log), 1388066205680 (data)
Did you compile properly the google play services in your build.gradle... you can follow the steps at the android developers site... http://developer.android.com/google/play-services/setup.html... and maybe you will have to use the gmaps api v3...
regards...!!

Installation error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED....by tamoghna

I have a problem with the Google maps activity......I'm getting the error of Installation error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED........following code of Google maps activity.............
package com.tommy.maps;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class Main extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.e("key", "ok");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.e("key", "ok2");
}
}
xml file in layout
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tommy.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.tommy.maps.Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY" />
<meta-data>
</meta-data>
</application>
</manifest>
I have posted the manifest and xml code and java code ......please tell me my error and tell me what to do for the error......
my log cat messages are:-
12-26 15:06:00.160: I/Choreographer(546): Skipped 31 frames! The application may be doing too much work on its main thread.
12-26 15:06:00.330: I/Choreographer(546): Skipped 52 frames! The application may be doing too much work on its main thread.
12-26 15:06:00.600: I/Choreographer(546): Skipped 80 frames! The application may be doing too much work on its main thread.
12-26 15:06:01.361: D/AndroidRuntime(1480): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
12-26 15:06:01.361: D/AndroidRuntime(1480): CheckJNI is ON
12-26 15:06:01.470: D/dalvikvm(1480): Trying to load lib libjavacore.so 0x0
12-26 15:06:01.490: D/dalvikvm(1480): Added shared lib libjavacore.so 0x0
12-26 15:06:01.590: D/dalvikvm(1480): Trying to load lib libnativehelper.so 0x0
12-26 15:06:01.590: D/dalvikvm(1480): Added shared lib libnativehelper.so 0x0
12-26 15:06:01.770: E/cutils-trace(1480): Error opening trace file: No such file or directory (2)
As you minimum api level is 8 so you need you SupportMapFragment besides MapFragment in your xml file. Change your layout as below :
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
In your MainActivity extend FragmentActivity besides Activity as below:
public class Main extends FragmentActivity{
Try to place this in your xml file: <fragment....../>
and even try to generate api key try to place it....
and even
Just delete "gen"folder . It build automatically.
Application will work fine.

Error Fatal Exception: main & Inflating Class Fragment

I am following this tutorial , i used the original files provided in the tutorial but facing same problem.searched for many pre asked questions but could not find way to repair my error.I m having error of "Unfortunately app has stopped" I got errors in logcat as follow.
Logcat of my project
11-30 17:35:36.852: E/Trace(836): error opening trace file: No such file or directory (2)
11-30 17:35:37.432: D/AndroidRuntime(836): Shutting down VM
11-30 17:35:37.432: W/dalvikvm(836): threadid=1: thread exiting with uncaught exception
(group=0x40a13300)
11-30 17:35:37.452: E/AndroidRuntime(836): FATAL EXCEPTION: main
11-30 17:35:37.452: E/AndroidRuntime(836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gmap/com.example.gmap.MainActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
.java file as follows
public class MainActivity extends FragmentActivity
implements OnMapClickListener {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
mMap.setOnMapClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onMapClick(LatLng position) {
mMap.addMarker(new MarkerOptions()
.position(position)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
}
}
Manifest file as follow
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gmap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- You must insert your own Google Maps for Android API v2 key in here. -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="I inserted key obtained" />
<activity
android:name="com.example.gmap.MainActivity"
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>
Your Java code seems to be correct. Try to remove the implements onClickListener and onClick method just for a try. Your manifest needs some changing. I suggest adding these elements:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.nurakanbpo.mygenie.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.nurakanbpo.mygenie.MAPS_RECEIVE" />
Your minSdkVersion is 13 for which you dont need supportmapfragment. You can use mapfragment.
Also since revision 13 of google play services was released you need to add this element to your you application tag:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />

google maps android api v2 using supportmapfragment

I tried to install project present in tutorial:
All It's ok but when run project, logcat say:
"Could not find class 'maps.ag.l', referenced from method maps.ah.an.a"
The map is empty and logcat say:
" Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
I have changed package name from "in.wptrafficanalyzer.locationgooglemapv2demo" to "it.appatwork" and i have got the apikey for android maps apiV2 with my sha1.
I have android 2.3.3
Please help me!
Mainactivity:
package it.appatwork.locationgooglemapv2demo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable (getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
System.out.println("ok");
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
activity_main.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=".MainActivity" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
AndoridManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.appatwork.locationgooglemapv2demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="it.appatwork.locationgooglemapv2demo.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBgkEwv0Z4O2t27avrve_33N33QY0wHNXg"/>
</application>
</manifest>
UPDATE:
this is the logcat output:
07-24 23:11:40.849: W/dalvikvm(6472): VFY: unable to resolve instance field 24
07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/p/w; (718)
07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/p/w;' failed
07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/aq/as; (5347)
07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/aq/as;' failed
07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/ag/l; (4576)
07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/ag/l;' failed
07-24 23:11:41.149: E/dalvikvm(6472): Could not find class 'maps.ag.l', referenced from method maps.ah.an.a
07-24 23:11:41.149: W/dalvikvm(6472): VFY: unable to resolve new-instance 4420 (Lmaps/ag/l;) in Lmaps/ah/an;
07-24 23:11:41.359: I/ApplicationPackageManager(6472): cscCountry is not German : WIN
07-24 23:11:47.069: W/Google Maps Android API(6472): Please add <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> into AndroidManifest.xml to ensure correct behavior under poor connectivity conditions.
07-24 23:11:47.069: I/Google Maps Android API(6472): Failed to contact Google servers. Another attempt will be made when connectivity is established.
07-24 23:11:59.009: W/IInputConnectionWrapper(6472): getExtractedText on inactive InputConnection
07-24 23:11:59.009: W/IInputConnectionWrapper(6472): getExtractedText on inactive InputConnection
07-24 23:12:02.289: E/Google Maps Android API(6472): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
First of all the two problem you are describing are not related one to another, you main problem is here:
Failed to load map. Error contacting Google servers. This is probably
an authentication issue (but could be due to network errors).
This means that you have some kind of problem with you permissions in the manifest file, or with you configuration in the Google API's console.
Please go over all the steps of this two blog post, Google Maps API V2 key and Google Maps API V2, and commit all the steps, if you still have problems post here your code and updated logcat message.
UPDATE:
You package name:
package="it.appatwork.locationgooglemapv2demo"
does not match the package name you specified in the permissions:
permission
android:name="it.appatwork.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="it.appatwork.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"/>
I think it's case-sensitive so try to change it to:
permission
android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"/>

Categories

Resources