0

I am loading different view depending on the network state. When the network is available, i am loading a fragment and when network is not available, i am loading an image. The code is as shown below

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (!isConnectedToNetwork()) {


        setContentView(R.layout.no_internet_connection);
        Toast.makeText(getApplicationContext(), "Not connected to internet. Cannot display the map.", Toast.LENGTH_LONG).show();
    }       
}

@Override

protected void onResume() {
    super.onResume();


    if (isConnectedToNetwork()) {
            setContentView(R.layout.activity_display_map);
            setUpViews();

    } else {
        stopService(new Intent(getApplicationContext(), VoiceLaunchService.class));
        setContentView(R.layout.no_internet_connection);
        Toast.makeText(getApplicationContext(), "Not connected to internet. Cannot display the map.", Toast.LENGTH_LONG).show();
    }
}

private void setUpViews() {

    map = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
}

Steps to reproduce Error:

Step1: Launch application with device connected to internet. Map is seen Step2: Disconnect the device from internet (app is sent to background). Now the app shows the "No internet connection" page (app is brought to front). Step3: Now again connect to the internet.The following error is show below

java.lang.RuntimeException: Unable to resume activity. android.view.InflateException: Binary XML file line #2: Error inflating class fragment

My layout file is as shown below

 <?xml version="1.0" encoding="utf-8"?>
 <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.MapFragment"/>

I didnt understand where i am going wrong. I have gone through all the solutions on this site, but in vain. Any help would be grateful

chaitu
  • 1,036
  • 5
  • 20
  • 39

1 Answers1

-1

Extends your activity with FragmentActivity

  1. YourActivity extends FragmentActivity

2.Change setUpViews() method to

private void setUpViews() {
 map = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
DeepakPanwar
  • 1,389
  • 14
  • 22