抛出OutOfMemoryError

时间:2016-01-21 23:33:56

标签: android out-of-memory

我关注了如何在Android上制作标签式应用的在线视频。在视频上它工作正常,但我收到此错误,无法找到任何解决方案。

这是一个非常基本的应用程序,错误没有意义。该应用程序只有3个空片段和一个主要活动。我甚至没有任何数据。该错误甚至没有报告我的代码的任何行!

    01-21 15:58:47.474 2382-2382/com.laiq.laiq E/art: Throwing OutOfMemoryError "Failed to allocate a 23700984 byte allocation with 16777216 free bytes and 18MB until OOM"
01-21 15:58:47.478 2382-2382/com.laiq.laiq E/AndroidRuntime: Error reporting crash
                                                             java.lang.OutOfMemoryError: Failed to allocate a 23700984 byte allocation with 16777216 free bytes and 18MB until OOM
                                                                 at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
                                                                 at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:125)
                                                                 at java.lang.StringBuffer.append(StringBuffer.java:278)
                                                                 at java.io.StringWriter.write(StringWriter.java:123)
                                                                 at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:358)
                                                                 at com.android.internal.util.FastPrintWriter.appendLocked(FastPrintWriter.java:303)
                                                                 at com.android.internal.util.FastPrintWriter.write(FastPrintWriter.java:625)
                                                                 at com.android.internal.util.FastPrintWriter.append(FastPrintWriter.java:658)
                                                                 at java.io.PrintWriter.append(PrintWriter.java:691)
                                                                 at java.io.PrintWriter.append(PrintWriter.java:31)
                                                                 at java.lang.Throwable.printStackTrace(Throwable.java:324)
                                                                 at java.lang.Throwable.printStackTrace(Throwable.java:300)
                                                                 at android.util.Log.getStackTraceString(Log.java:340)
                                                                 at com.android.internal.os.RuntimeInit.Clog_e(RuntimeInit.java:59)
                                                                 at com.android.internal.os.RuntimeInit.access$200(RuntimeInit.java:43)
                                                                 at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:85)
                                                                 at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                                                                 at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

这是我的主要课程

public class MainActivity extends AppCompatActivity {

    private SectionsPagerAdapter mSectionsPagerAdapter;
    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);

        // List of all fragments
        List<Fragment> mFragmentList = new ArrayList<>();
        mFragmentList.add(new NewsFragment());
        mFragmentList.add(new OffersFragment());
        mFragmentList.add(new ProductsFragment());

        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), mFragmentList);

        // 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 fab = (FloatingActionButton) findViewById(R.id.fab);
//        fab.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();
//            }
//        });

    }


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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

我试着看看其他答案,但这没有意义,我在哪里请求任何记忆?

我的SectionsPagerAdapter

public class SectionsPagerAdapter extends FragmentPagerAdapter {

        List<Fragment> listFragments;

        public SectionsPagerAdapter(FragmentManager fm, List<Fragment> listFragments) {
            super(fm);
            this.listFragments = listFragments;
        }

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).
            return listFragments.get(position);
        }

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

0 个答案:

没有答案