user2084975
user2084975

Reputation: 1

Runtime Error: inflating class

Pretty simple question here, but I'm having a runtime error, as follows:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.maptest/com.example.maptest.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment

I've had this problem before, and my gut instinct is that it has something to do with the libraries maybe, but I'm not sure. I know there's a lot of questions like this on here, but they're very very case specific. I'm just wondering if there's anything that jumps out at ya'll as wrong with my code. I appreciate the help!

My Main activity file (MainActivity.java) is:

package com.example.maptest;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;  
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class MainActivity extends FragmentActivity {

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

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

private static final int ACTIVITY_CREATE = 0;

private void configureSettings() {
    Intent intent = new Intent(this, ConfigureSyncActivity.class);
    startActivityForResult(intent, ACTIVITY_CREATE);
}

private void setLimits() {
    Intent intent = new Intent(this, SetLimitsActivity.class);
    startActivityForResult(intent, ACTIVITY_CREATE);
}

private void violations() {
    Intent intent = new Intent(this, ViolationsActivity.class);
    startActivityForResult(intent, ACTIVITY_CREATE);
}

@Override
public boolean onOptionsItemSelected(MenuItem item){

    switch(item.getItemId()) {

    case R.id.limits:
        setLimits();
        return true;

    case R.id.sync:
        configureSettings();
        return true;

    case R.id.violations:
        violations();
        return true;


    }
    return super.onOptionsItemSelected(item);
}

}

And last but not least, my xml layout file:

 <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"/>

Upvotes: 0

Views: 179

Answers (1)

kriti
kriti

Reputation: 23

Try the following change in your xml layout file. It worked for me:

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

If that doesn't work try checking the class name hierarchy.

Upvotes: 1

Related Questions