0

I am trying to implement fragment tag, in my code so that I can use it with GoogleMap API. However just at the outset i am getting stuck because of an error "Binary XML File Line". I tried searching it in the forum but I was not able to solve it. Kindly help me understand this problem.

I am attaching all the files here my activity_main.xml

<LinearLayout 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="com.example.mapdemo.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</LinearLayout>

My activity_map.xml file goes as

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView 
            android:text="Loc:"
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            />

        <EditText 
            android:id="@+id/edt_locationName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center|center_vertical"
            android:ems="10"/>
        <Button 
            android:id="@+id/btn_GetLocation"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Go"
            android:layout_gravity="right|center_vertical"
            android:onClick="geoLocate"/>

    </LinearLayout>

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

</LinearLayout>

My main java file goes as

    package com.example.mapdemo;

import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends FragmentActivity {

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


    @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 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);
    }
}

Log cat is as below :-

05-19 14:45:15.763: E/AndroidRuntime(28629): FATAL EXCEPTION: main
05-19 14:45:15.763: E/AndroidRuntime(28629): Process: com.example.mapdemo, PID: 28629
05-19 14:45:15.763: E/AndroidRuntime(28629): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapdemo/com.example.mapdemo.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class fragment
05-19 14:45:15.763: E/AndroidRuntime(28629):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2436)
05-19 14:45:15.763: E/AndroidRuntime(28629):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2498)
05-19 14:45:15.763: E/AndroidRuntime(28629):    at android.app.ActivityThread.access$900(ActivityThread.java:179)
05-19 14:45:15.763: E/AndroidRuntime(28629):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
Shudy
  • 7,806
  • 19
  • 63
  • 98
pcsaunak
  • 289
  • 2
  • 12
  • did you setup all things needed to use maps?? – M090009 May 19 '15 at 09:42
  • No, i was trying to do it step by step, as this did not run i did not setup any other things in manifest file – pcsaunak May 19 '15 at 09:50
  • I have edited my answer. Please try it out. It might work. – Bidhan May 19 '15 at 09:57
  • Post the full stacktrace, including the nested "caused by" exceptions. – laalto May 19 '15 at 09:58
  • You need to set it up in order for it to work, because it connects to google gms you also need to add some permissions to your manifest checkout this https://developers.google.com/maps/documentation/android/start also checkout this link http://stackoverflow.com/questions/14825331/binary-xml-file-line-8-error-inflating-class-fragment-google-maps – M090009 May 19 '15 at 09:59
  • Let me try the permissions !!! – pcsaunak May 19 '15 at 10:46
  • So finally adding all the values in the manifest file solved the problem !!! Can any body share any good tutorials related to fragment and fragment activity – pcsaunak May 19 '15 at 14:07

2 Answers2

1

In your MainActivity, add the following import statement

import android.support.v4.app.Fragment;

Edit: I'm not sure if this will work, but try changing your fragment tag to this

<fragment
    android:id="@+id/map"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</fragment>
Bidhan
  • 10,607
  • 3
  • 39
  • 50
0

try to put the fragment inside the linearLayout tag