2

Can anybody explain why this error occurs? And what I can do to fix this problem? this is the first time i get problem like this. thank you for the help.

Stacktrace:

11-27 16:35:07.250: D/AndroidRuntime(18552): Shutting down VM
11-27 16:35:07.250: W/dalvikvm(18552): threadid=1: thread exiting with uncaught exception (group=0x4144b930)
11-27 16:35:07.255: E/AndroidRuntime(18552): FATAL EXCEPTION: main
11-27 16:35:07.255: E/AndroidRuntime(18552): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.agusharyanto.petalokasi/net.agusharyanto.petalokasi.DisplayCurrentLocActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2249)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.app.ActivityThread.access$700(ActivityThread.java:154)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.os.Looper.loop(Looper.java:137)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.app.ActivityThread.main(ActivityThread.java:5306)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at java.lang.reflect.Method.invokeNative(Native Method)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at java.lang.reflect.Method.invoke(Method.java:511)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at dalvik.system.NativeStart.main(Native Method)
11-27 16:35:07.255: E/AndroidRuntime(18552): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:342)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.app.Activity.setContentView(Activity.java:1928)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at net.agusharyanto.petalokasi.DisplayCurrentLocActivity.onCreate(DisplayCurrentLocActivity.java:41)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.app.Activity.performCreate(Activity.java:5255)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213)
11-27 16:35:07.255: E/AndroidRuntime(18552):    ... 11 more
11-27 16:35:07.255: E/AndroidRuntime(18552): Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
11-27 16:35:07.255: E/AndroidRuntime(18552): <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
11-27 16:35:07.255: E/AndroidRuntime(18552):    at maps.af.cf.a(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at maps.af.ay.a(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at maps.af.al.a(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at maps.af.be.a(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at maps.af.bd.a(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at cmj.onTransact(SourceFile:107)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.os.Binder.transact(Binder.java:310)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at com.google.android.gms.dynamic.a$4.b(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at com.google.android.gms.dynamic.a.a(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:900)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1184)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
11-27 16:35:07.255: E/AndroidRuntime(18552):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:682)
11-27 16:35:07.255: E/AndroidRuntime(18552):    ... 21 more

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="net.agusharyanto.petalokasi"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />

<permission
    android:name="net.agusharyanto.petalokasi.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<uses-permission android:name="net.agusharyanto.petalokasi.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"
    android:theme="@style/AppTheme" >
    <activity
        android:name="net.agusharyanto.petalokasi.DisplayCurrentLocActivity"
        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.gms.version" 
                 android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAkJYisD9-6HB8D1ggkkWKZVtgNCLg8Fyk" />
</application>

</manifest>

DisplayCurrentLocActivity.java

 public class DisplayCurrentLocActivity extends FragmentActivity {
GoogleMap googlemap;
MarkerOptions markerOptions;
LatLng latLng;
LatLng prevLatLng = null;
Marker marker = null;
ArrayList<LatLng> arrline = new ArrayList<LatLng>();
private LocationManager locManager;
private LocationListener locListener;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.current_loc);

    FragmentManager fragmentManager = getSupportFragmentManager();
    SupportMapFragment supportMapFragment = (SupportMapFragment) fragmentManager
            .findFragmentById(R.id.mapcurrloc);

    // Getting a reference to the map
    googlemap = supportMapFragment.getMap();
    initLocationManager();
}

/**
 * Initialize the location manager.
 */
private void initLocationManager() {
    locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locListener = new LocationListener() {
        // method ini akan dijalankan apabila koordinat GPS berubah
        public void onLocationChanged(Location newLocation) {

            displayCurrentLoctoMap(newLocation);
        }

        public void onProviderDisabled(String arg0) {

        }

        public void onProviderEnabled(String arg0) {
            Location location = locManager
                    .getLastKnownLocation(LocationManager.GPS_PROVIDER);
            displayCurrentLoctoMap(location);
        }

        public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
        }
    };
    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
            locListener);
    Location location = locManager
            .getLastKnownLocation(LocationManager.GPS_PROVIDER);
    displayCurrentLoctoMap(location);
}

/**
 * This method will be called when current position changed is submitted via
 * the GPS.
 *
 * @param newLocation
 */
protected void displayCurrentLoctoMap(Location newLocation) {
    try {
        LatLng currlok = new LatLng(newLocation.getLatitude(),
                newLocation.getLongitude());

        if (marker != null)
            marker.remove();
        markerOptions = new MarkerOptions().position(currlok)
                .title("Current Location")
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher));

        googlemap.moveCamera(CameraUpdateFactory.newLatLngZoom(currlok, 15));
         // call and execute ReversGeocoding Task
          new ReverseGeocodingTask(getBaseContext()).execute(currlok);

    } catch (NullPointerException e) {
        Toast.makeText(DisplayCurrentLocActivity.this,"Can't get gps location, make sure your gps is enable",Toast.LENGTH_LONG).show();
    }
}

private class ReverseGeocodingTask extends AsyncTask<LatLng, Void, String>{
    Context mContext;

    public ReverseGeocodingTask(Context context){
        super();
        mContext = context;
    }

    // Finding address using reverse geocoding
    @Override
    protected String doInBackground(LatLng... params) {
        Geocoder geocoder = new Geocoder(mContext);
        double latitude = params[0].latitude;
        double longitude = params[0].longitude;

        List<Address> addresses = null;
        String addressText="";

        try {
            addresses = geocoder.getFromLocation(latitude, longitude,1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if(addresses != null && addresses.size() > 0 ){
            Address address = addresses.get(0);

            addressText = String.format("%s, %s, %s",
            address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
            address.getLocality(),
            address.getCountryName());
        }

        return addressText;
    }

    @Override
    protected void onPostExecute(String addressText) {
        // Setting the snippet for the marker.
        // This will be displayed on taping the marker
        Log.d("TAG","Alamat:"+addressText);
        markerOptions.snippet(addressText);
        marker = googlemap.addMarker(markerOptions);

    }
}

}
0

1 Answer 1

2
Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:

Add this is manifest

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your answer bro, but why when i run this code it didnt show the map that i want. it just show white screen without show the map that i give. and there's no error. *sorry for my english.
@user2268708 you need to enable maps for android in the google api console and you will need the right key in manifest. if you do it right you will see the map. follow developers.google.com/maps/documentation/android

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.