0

I have a problem with my android application. It worked fine before, but it started crashing immediately after start without any errors and I can't figure out why. I have commented (//) a lot of code in my classes and left there only things important for working, but still the same problem. I have a mainActivity and 2 fragments.

My project hiearchy

When I created fragments it automatically created folder layout and put java classes there. Fragment java classes (List, Set):

public class List extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_list, container, false);
    }
}

Main activity class:

public class MainActivity extends AppCompatActivity {

    /**
     * The {@link android.support.v4.view.PagerAdapter} that will provide
     * fragments for each of the sections. We use a
     * {@link FragmentPagerAdapter} derivative, which will keep every
     * loaded fragment in memory. If this becomes too memory intensive, it
     * may be best to switch to a
     * {@link android.support.v4.app.FragmentStatePagerAdapter}.
     */
    private SectionsPagerAdapter mSectionsPagerAdapter;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
    private ViewPager mViewPager;

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

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(mViewPager);

        FloatingActionButton addButton = (FloatingActionButton) findViewById(R.id.add);
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

    }

    /**
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch(position) {
                case 0:
                    return new Set();
                case 1:
                    return new List();
                default:
                    return null;
            }
        }

        @Override
        public int getCount() {
            // Show 3 total pages.
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "ZADÁVÁNÍ";
                case 1:
                    return "SEZNAM";
            }
            return null;
        }
    }
}

activity_main.xml (auto-generated):

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="cz.sudoman281.kubirovacikalkulacka.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        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:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

fragments .xml files:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".layout.List">

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="List"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView6" />

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </GridLayout>
</FrameLayout>
  • 1
    Use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Jan 01 '17 at 13:50
  • Try after returning `1` instead of `2` – ρяσѕρєя K Jan 01 '17 at 13:51
  • @CommonsWare I'm getting only this: http://pastebin.com/HTKwnH3D –  Jan 01 '17 at 14:02
  • @ρяσѕρєяK still not working :/ –  Jan 01 '17 at 14:03
  • Did you try clean the project or change main activity to another in androidmanifest? – Ricardo Romero Benítez Jan 01 '17 at 14:07
  • 1
    That is not a Java stack trace. Note that sometimes Android Studio's filters get a little aggressive, so make sure that you are not filtering by application. If you do not get a stack trace, then you are not crashing. – CommonsWare Jan 01 '17 at 14:10
  • @RicardoRomeroBenítez I have, but still doesn't work :( –  Jan 01 '17 at 16:46
  • @CommonsWare When I disable filters http://pastebin.com/jmEjSuAS –  Jan 01 '17 at 16:47
  • @sudoman281 Start the app in debug mode, set a breakpoint on the first line in `onCreate` and keep steeping over(F8) till you get the crash. – K Neeraj Lal Jan 01 '17 at 16:51
  • The only stack trace in there is from some Huawei code, not your app. What makes you think that your app is crashing? – CommonsWare Jan 01 '17 at 17:05
  • @KNeerajLal thank you very much! It helped me to find out what was wrong :) When I created my project it automatically added floating button. I have deleted it from xml file, but I forgot to delete onlcick listener from Java class, however it's weird, that Android Studio didn't notice me. You can post your answer :) –  Jan 01 '17 at 17:06
  • @sudoman281 Glad I could help. Posted an answer. :) – K Neeraj Lal Jan 02 '17 at 05:54

2 Answers2

1

From your log output, I saw this line:

01-01 15:01:58.206 7457-7457/cz.sudoman281.kubirovacikalkulacka W/System: ClassLoader referenced unknown path: /data/app/cz.sudoman281.kubirovacikalkulacka-1/lib/arm64

I guess there is something wrong with your native libraries, double check your Make or CMake buid files, make sure you're loading your native libraries correctly from the Java class.

Another thing if you're running your app on a device/emulator with Android Nougat, you may need to check that your native libraries are not linking against non-NDK libraries as described here: https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk

Mina Wissa
  • 10,923
  • 13
  • 90
  • 158
  • Thank you for answer :) I'm not sure what Make and CMake are :/ This is my build.gradle: http://pastebin.com/vaQ4baYZ. I'm running android 6. –  Jan 01 '17 at 16:48
  • I'm not sure, try to decrement the compile SDK and build tools version to 24 and see what happens. – Mina Wissa Jan 01 '17 at 17:02
1

The logcat filters does not always show logs when the app is getting started up. I faced a similar issue when integrating a library. This is how I found where the issue is.

Start the app in debug mode, set a breakpoint on the first line in onCreate method and keep steping over(F8) till you get the crash.

K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33