Question

Im creating an application in which I have to show map when the button is clicked. But when the map button is clicked instead of showing map the application crash and it said "Unfortunately, 'Application' has stopped" here is my code:

java file:

package com.example.jamaattiming;

import android.os.Bundle;
import android.app.Activity;
//import android.app.FragmentTransaction;
import android.view.Menu;
import com.example.jamaat_times.R;
import com.google.android.gms.maps.GoogleMap;
//import com.google.android.gms.maps.MapFragment;

public class TagYourself extends Activity {

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

        /* MapFragment mMapFragment = MapFragment.newInstance();
         FragmentTransaction fragmentTransaction =
                 getFragmentManager().beginTransaction();
         fragmentTransaction.add(R.id.map, mMapFragment);
         fragmentTransaction.commit();

         GoogleMap maps;
         maps=(((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap());*/


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.tag_yourself, menu);
        return true;
    }

}

here's the xml file:

<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:orientation="vertical" 
    android:background="#808080">

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

manifest file:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.jamaat_times"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
    <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_jamaat"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.jamaattiming.Splash"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.jamaattiming.MainPage"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.CLEARSCREEN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.jamaattiming.Qibla"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="com.example.COMPASS" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.example.jamaattiming.JamaatFinder"
            android:label="@string/title_activity_jamaat_finder" >
        </activity>

        <activity
            android:name="com.example.jamaattiming.QiblaFinder"
            android:label="@string/title_activity_qibla_finder" >
        </activity>

        <activity
            android:name="com.example.jamaattiming.TagYourself"
            android:label="@string/title_activity_tag_yourself" >
         </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="my key" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name="com.example.jamaattiming.NearbySearch"
            android:label="@string/title_activity_nearby_search" >
        </activity>

        <activity
            android:name="com.example.jamaattiming.ManualSearch"
            android:label="@string/title_activity_manual_search" >
        </activity>


    </application>

</manifest>

here is the log cat:

04-01 00:32:36.587: I/SurfaceTextureClient(18546): [STC::queueBuffer] (this:0x518786b0) fps:0.88, dur:2279.85, max:1974.08, min:305.77 04-01 00:32:36.990: V/Provider/Settings(18546): invalidate [system]: current 214 != cached 0 04-01 00:32:37.020: D/ActivityThread(18546): installProvider: 04-01 00:32:37.034: V/Provider/Settings(18546): from db cache, name = sound_effects_enabled , value = 0 04-01 00:32:37.223: D/mylog(18546): Wifi State true 04-01 00:32:38.102: D/ActivityThread(18546): getPackageInfo: securityViolation=true 04-01 00:32:38.102: W/asset(18546): AssetManager-->addDefaultAssets CIP path not exsit! 04-01 00:32:38.741: I/Google Maps Android API(18546): Google Play services client version: 4242000 04-01 00:32:39.025: I/Google Maps Android API(18546): Google Play services package version: 4324034 04-01 00:32:39.538: D/AndroidRuntime(18546): Shutting down VM 04-01 00:32:39.538: W/dalvikvm(18546): threadid=1: thread exiting with uncaught exception (group=0x419b19a8) 04-01 00:32:39.709: E/AndroidRuntime(18546): FATAL EXCEPTION: main 04-01 00:32:39.709: E/AndroidRuntime(18546): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jamaat_times/com.example.jamaattiming.TagYourself}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.ActivityThread.access$600(ActivityThread.java:162) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.os.Handler.dispatchMessage(Handler.java:107) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.os.Looper.loop(Looper.java:194) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.ActivityThread.main(ActivityThread.java:5371) 04-01 00:32:39.709: E/AndroidRuntime(18546): at java.lang.reflect.Method.invokeNative(Native Method) 04-01 00:32:39.709: E/AndroidRuntime(18546): at java.lang.reflect.Method.invoke(Method.java:525) 04-01 00:32:39.709: E/AndroidRuntime(18546): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 04-01 00:32:39.709: E/AndroidRuntime(18546): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 04-01 00:32:39.709: E/AndroidRuntime(18546): at dalvik.system.NativeStart.main(Native Method) 04-01 00:32:39.709: E/AndroidRuntime(18546): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 04-01 00:32:39.709: E/AndroidRuntime(18546): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.Activity.setContentView(Activity.java:1881) 04-01 00:32:39.709: E/AndroidRuntime(18546): at com.example.jamaattiming.TagYourself.onCreate(TagYourself.java:16) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.Activity.performCreate(Activity.java:5122) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 04-01 00:32:39.709: E/AndroidRuntime(18546): ... 11 more 04-01 00:32:39.709: E/AndroidRuntime(18546): 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: 04-01 00:32:39.709: E/AndroidRuntime(18546): 04-01 00:32:39.709: E/AndroidRuntime(18546): at maps.e.ci.a(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at maps.e.ay.a(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at maps.e.ay.a(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at maps.e.al.a(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at maps.e.bh.a(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at maps.e.bg.a(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at etu.onTransact(SourceFile:107) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.os.Binder.transact(Binder.java:310) 04-01 00:32:39.709: E/AndroidRuntime(18546): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at com.google.android.gms.dynamic.a$4.b(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at com.google.android.gms.dynamic.a.a(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at com.google.android.gms.dynamic.a.onCreateView(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.Fragment.performCreateView(Fragment.java:1695) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:861) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1137) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.app.Activity.onCreateView(Activity.java:4735) 04-01 00:32:39.709: E/AndroidRuntime(18546): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680) 04-01 00:32:39.709: E/AndroidRuntime(18546): ... 21 moreenter code here

Was it helpful?

Solution

Take a look at this line of your logcat:

 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: 04-01 00:32:39.709: 
E/AndroidRuntime(18546): <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 04-01 00:32:39.709: E/AndroidRuntime(18546):   at maps.e.ci.a(Unknown Source)

Looks like you forgot to add the permission:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

to your AndroidManifest xml file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top