0

I have a little issue with my android app. So i have a maps fragment, and i'm trying to put a listview under it. The error occurs when i Try to populate the listview, it does show empty before, but once i bind it to the adapter it gives me this error :

01-21 20:43:17.635 19597-19597/boxcom.secondattempt E/AndroidRuntime: FATAL EXCEPTION: main 01-21 20:43:17.635 19597-19597/boxcom.secondattempt E/AndroidRuntime: Process: boxcom.secondattempt, PID: 19597 01-21 20:43:17.635 19597-19597/boxcom.secondattempt E/AndroidRuntime: android.view.InflateException: Binary XML file line #22: Error inflating class fragment

Here is my XML :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/app_bar_main_menu" tools:context="boxcom.secondattempt.MainMenu">


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/map"
        android:layout_alignParentStart="true"
        android:layout_marginTop="70dp"
        android:weightSum="1">

        <fragment
            android:id="@+id/map"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            class="com.google.android.gms.maps.MapFragment"
            android:layout_weight="0.75"
            android:layout_gravity="top|bottom"></fragment>

        <ListView
                    android:id="@+id/listv"
                    android:background="@color/com_facebook_blue"
                    android:layout_width="354dp"
                    android:layout_height="187dp"></ListView>

    </LinearLayout>


</RelativeLayout>

and where I populate :

public void init_endroits()
{
    Place A = new Place();
    Place B = new Place();
    Place C = new Place();

    A.setName("Café A");
    B.setName("Restaurant B");
    C.setName("Musée C");
    A.setDescription("C'est un café");
    B.setDescription("C'est un restaurant");
    C.setDescription("C'est un Musée");

    ListView LV = (ListView)findViewById(R.id.listv);
    Endroits.add(A);
    Endroits.add(B);
    Endroits.add(C);
    adapter = new ArrayAdapter<Place>(this,R.layout.activity_main_menu,Endroits);
    LV.setAdapter(adapter);
    LV.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1,
                                int position, long arg3) {
            Place X = Endroits.get(position);
            Toast.makeText(MainMenu.this, X.getDescription().toString(), Toast.LENGTH_SHORT).show();
        }
    });


}

I call this method after everything is loaded, when I press a button in the navbar.

Can you help me please?

Michele Lacorte
  • 5,323
  • 7
  • 32
  • 54

1 Answers1

0

I am just guessing this is a duplicate of “Error inflating class fragment” with google map stackoverflow question, as you are using support AppCompatActivity with MapFragment.

Replace MapFragment with SupportMapFragment, and that should clear up this specific crash.

Community
  • 1
  • 1
MikeL
  • 5,385
  • 42
  • 41
  • I've just changed every MapFragment to SupportMapFragment, changed it in the xml too by using com.google.android.gms.maps.SupportMapFragment instead, same error :( – user3591536 Jan 21 '16 at 21:03
  • Did you try using FragmentActivity instead? – MikeL Jan 21 '16 at 21:11
  • I'm using a navbar + sidebar layout, if i make it extend FragmentActivity instead i think it might break it, no? – user3591536 Jan 21 '16 at 21:13
  • I just changed it, and commented out the navbar part, it still gives me the same goddamn error >:( ty tho – user3591536 Jan 21 '16 at 21:16
  • I removed the fragment and left only the list view, gave me this error : ArrayAdapter requires the resource ID to be a TextView – user3591536 Jan 21 '16 at 21:29
  • It's fixed ! I fixed the text view issue, then put back the fragment and i don't have the error anymore, thanks for the help guys – user3591536 Jan 21 '16 at 21:34
  • What was the issue exactly? Please share it so that it will help others. – MikeL Jan 22 '16 at 11:43