0

i'm a bit stuck in this task. I have an app which displays a main fragment embedding google maps, now i would like to replace it with another fragment showing some charts when the user clicks a send button inside a drawer menu list.

When i click send application get stuck, giving me the hated "Application Not Responding". However, if i change the android:name field into the same of the maps fragment, it works and display the map correctly.

Main activity snippet where i launch maps fragment

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.activity_main);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();


    mapsFragment = new MapsFragment();
    getSupportFragmentManager().beginTransaction()
            .add(R.id.maincontainer,mapsFragment)
            .commit();

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

}

Main Activity snippet where i launch the charts fragment

    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        Snackbar snackbar;
        Fragment fragment = null;
        switch(item.getItemId()){
            case R.id.nav_manage:
                snackbar = Snackbar
                        .make(coordinatorLayout, "manage", Snackbar.LENGTH_LONG);
                snackbar.show();
                break;
            case R.id.nav_share:
                snackbar = Snackbar
                        .make(coordinatorLayout, "share", Snackbar.LENGTH_LONG);
                snackbar.show();
                break;
            case R.id.nav_send:
                snackbar = Snackbar
                        .make(coordinatorLayout, "send", Snackbar.LENGTH_LONG);
                snackbar.show();
                fragment = new ChartsFragment();
                break;
            case R.id.nav_view:
                snackbar = Snackbar
                        .make(coordinatorLayout, "view", Snackbar.LENGTH_LONG);
                snackbar.show();
                break;
        }
        if(fragment != null){
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.maincontainer,fragment)
                    .commit();
        }
        // Highlight the selected item has been done by NavigationView
        item.setChecked(true);
        // Set action bar title
        //setTitle(item.getTitle());
        DrawerLayout drawer = (DrawerLayout)
findViewById(R.id.activity_main);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

MapsFragment onCreate

 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_maps, container, false);
        SupportMapFragment mMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
        mMapFragment.getMapAsync(this);
        mContext = getActivity();
        return rootView;
    }

ChartsFragment onCreate

 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_charts, container, false);
    return rootView;
}

Main appbar xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:id="@+id/coordinator_layout_app_bar_main"
    tools:context="com.fabio.gis.geotag.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_activity" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/place_marker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="80dp"
        android:layout_gravity="bottom|end"
        android:layout_marginRight="16dp"
        app:backgroundTint="@color/secondaryColorAccent"
        app:elevation="6dp"
        app:pressedTranslationZ="12dp"
        android:src="@drawable/ic_marker" />
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/send_positions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        app:elevation="6dp"
        app:backgroundTint="@color/colorAccent"
        app:pressedTranslationZ="12dp"
        android:layout_margin="16dp"
        android:src="@drawable/ic_play_arrow_white_24dp" />
</android.support.design.widget.CoordinatorLayout>

Maps fragment

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map_ui"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

Charts Fragment

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/charts_ui"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

     <fragment xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/charts"
         android:name="com.fabio.gis.geotag.ChartsFragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent">
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Hello World!" />

     </fragment>
</RelativeLayout>

I already tried to replace

android:name="com.fabio.gis.geotag.ChartsFragment"

with

class="com.fabio.gis.geotag.ChartsFragment"

Nothing changed.

Thanks in advance for your support. I realize i'm a beginner in android, maybe i'm struggling for just a stupid rookie mistake.

After a while it remain in ANR it gave me the following stacktrace error

03-06 17:11:43.322 7033-7033/? E/AndroidRuntime:     at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                                                 at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                 at com.fabio.gis.geotag.ChartsFragment.onCreateView(ChartsFragment.java:20)
                                                 at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1065)
                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
                                                 at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1370)
                                                 at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2415)
                                                 at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                                                 at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                 at com.fabio.gis.geotag.ChartsFragment.onCreateView(ChartsFragment.java:20)
                                                 at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1065)
                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
                                                 at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1370)
                                                 at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2415)
                                                 at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                                                 at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                 at com.fabio.gis.geotag.ChartsFragment.onCreateView(ChartsFragment.java:20)
                                                 at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1065)
                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
                                                 at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1370)
                                                 at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2415)
                                                 at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                                                 at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:426)

                                             read: unexpected EOF!
Fabio
  • 782
  • 4
  • 8
  • 25

1 Answers1

0

To whom it may concern, the error was caused by some inconsistent library references versions in gradle file, causing possible unexpected runtime exceptions.

The problem has been tackled in this thread

Hope it can save hours to someone in future.

Community
  • 1
  • 1
Fabio
  • 782
  • 4
  • 8
  • 25