简体   繁体   English

Android应用程序启动后崩溃,没有任何错误

[英]Android application crashes after startup without any errors

I have a problem with my android application. 我的Android应用程序有问题。 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. 我有一个mainActivity和2个片段。

我的项目

When I created fragments it automatically created folder layout and put java classes there. 当我创建片段时,它会自动创建文件夹布局并在其中放置Java类。 Fragment java classes (List, Set): 片段Java类(列表,集合):

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): activity_main.xml(自动生成):

<?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: 片段.xml文件:

<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>

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 01-01 15:01:58.206 7457-7457 / cz.sudoman281.kubirovacikalkulacka W / System:ClassLoader引用的未知路径:/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. 我想本机库有问题,请仔细检查Make或CMake buid文件,确保从Java类正确加载了本机库。

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 另一件事,如果您正在使用Android Nougat在设备/仿真器上运行应用程序,则可能需要检查本地库是否未按非NDK库链接,如下所述: https : //developer.android.com/about /versions/nougat/android-7.0-changes.html#ndk

The logcat filters does not always show logs when the app is getting started up. 在启动应用程序时,logcat筛选器并不总是显示日志。 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. 在调试模式下启动应用程序,在onCreate方法的第一行上设置一个断点,然后继续跳过(F8),直到崩溃为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM