Farshad Kazemi
Farshad Kazemi

Reputation: 358

Error in using Fragment

I'm going to use Google Map V2 in my application, so I'm following tutorials on the web like this.

But when I use fragment tag in XML layout and run application, it jumped to DEBUG window(view) of eclipse.

I've checked my codes line by line, and first error appears when I use fragment tag in XML layout!

I've created a test application (as below) and got error again.

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

<fragment 
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</LinearLayout>

and my java class:

public class Main extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    }
}

I know that when I use fragment tag in my layout, I'll got error.

Could you please tell me what is wrong !

Upvotes: 0

Views: 27

Answers (1)

hareesh J
hareesh J

Reputation: 530

Place the following code in the application tag in manifest he missed that line in that example

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

and replace the following in the layout file

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

Upvotes: 2

Related Questions