Android:应用程序在模拟器上运行,但在我的手机上崩溃 [英] Android: App runs on emulator but it crashes on my mobile phone

查看:27
本文介绍了Android:应用程序在模拟器上运行,但在我的手机上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在模拟器 Nexus 5(Android 7.0,API 24)上运行,但是当我尝试使用onClick"打开另一个活动时,它在我的手机(Samsung J5 Android 5.1.1)上崩溃.

My app works on the emulator Nexus 5(Android 7.0, API 24) but it crashes on my mobile phone(Samsung J5 Android 5.1.1) in a precise activity when I try to open another activity with an "onClick".

这是崩溃的活动

public class CuboActivity 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_cubo);
        Toast.makeText(getApplicationContext(),"Premi le foto per vederle ingradite oppure visita il menu per vederle una dopo l'altra",Toast.LENGTH_LONG).show();
        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);
    }

    @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_cubo, 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.
        Toast.makeText(getApplicationContext(),"Per alcune immagini gira il telefono",Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(this, FotoCuboActivity.class);
        startActivity(intent);
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private static final String ARG_SECTION_NUMBER = "section_number";

        public PlaceholderFragment() {
        }

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState)
        {
            switch (getArguments().getInt(ARG_SECTION_NUMBER))
            {
                case 1:
                    View rootView = inflater.inflate(R.layout.fragment_cubo, container, false);
                    return rootView;

                case 2:
                    View rootView2 = inflater.inflate(R.layout.fragment_cubo2, container, false);
                    return rootView2;

                case 3:
                    View rootView3 = inflater.inflate(R.layout.fragment_cubo3, container, false);
                    return rootView3;

                case 4:
                    View rootView4 = inflater.inflate(R.layout.fragment_cubo4, container, false);
                    return rootView4;

                default:
                    View rootView0 = inflater.inflate(R.layout.fragment_cubo, container, false);
                    return rootView0;
            }
        }
    }

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

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

        @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 PlaceholderFragment.newInstance(position + 1);
        }

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

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "CONSEGNA";
                case 1:
                    return "LAVORO";
                case 2:
                    return "RISULTATO";
                case 3:
                    return "RELAZIONE";
            }
            return null;
        }
    }

    public void onClick(View arg0)
    {
        switch(arg0.getId())
        {
            case R.id.segaCircolare:
                Intent intent = new Intent(this,FragmentCuboActivity.class);
                startActivity(intent);
                break;
            case R.id.lavorazioneCubo:
                Intent intent2 = new Intent(this,FragmentCubo2Activity.class);
                startActivity(intent2);
                break;
            case R.id.prodottiFiniti:
                Toast.makeText(getApplicationContext(),"Gira il telefono",Toast.LENGTH_SHORT).show();
                Intent intent3 = new Intent(this,FragmentCubo3Activity.class);
                startActivity(intent3);
                break;
            case R.id.modelloCubo:
                Intent intent4 = new Intent(this,FragmentCubo4Activity.class);
                startActivity(intent4);
                break;
            case R.id.cuboAlto:
                Intent intent5 = new Intent(this,FragmentCubo5Activity.class);
                startActivity(intent5);
                break;
            case R.id.cuboFrontale:
                Intent intent6 = new Intent(this,FragmentCubo6Activity.class);
                startActivity(intent6);
                break;
            case R.id.cuboIntermedio:
                Intent intent7 = new Intent(this,FragmentCubo7Activity.class);
                startActivity(intent7);
                break;
            case R.id.bottoneRelazione:
                Uri uri = Uri.parse("https://docs.google.com/document/d/1J4KJJRzSnY5PSdQYoh6hrTKarl0ID0dtX8TqLga6-dY/edit?usp=sharing");
                Intent intent0 = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent0);
                break;
        }
    }
}

这是这个活动的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:text="@string/Procedimento1"
        android:layout_width="321dp"
        android:layout_height="wrap_content"
        android:id="@+id/textView14"
        android:layout_gravity="center"
        android:layout_marginTop="15dp"
        android:gravity="center" />

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@drawable/lavorazionecubo"
        android:id="@+id/lavorazioneCubo"
        android:layout_marginTop="15dp"
        android:layout_gravity="center"
        android:contentDescription="@string/Vuoto"
        android:onClick="onClick"/>

    <TextView
        android:text="@string/Procedimento2"
        android:layout_width="351dp"
        android:layout_height="wrap_content"
        android:id="@+id/textView15"
        android:layout_gravity="center"
        android:layout_marginTop="15dp"
        android:gravity="center" />

    <RelativeLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="15dp">

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@drawable/modellocubo"
            android:id="@+id/modelloCubo"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_marginRight="40dp"
            android:layout_marginEnd="40dp"
            android:contentDescription="@string/Vuoto"
            android:onClick="onClick"/>

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@drawable/prodottifiniti"
            android:id="@+id/prodottiFiniti"
            android:layout_marginLeft="40dp"
            android:layout_marginStart="40dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:contentDescription="@string/Vuoto"
            android:onClick="onClick" />

    </RelativeLayout>
</LinearLayout>

这是上一个活动因为崩溃而没有打开的活动之一

This is one of the activities which the previous activity doesn't open because it crashes

public class FragmentCubo2Activity extends AppCompatActivity {

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

这是它的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/lavorazionecubo">
</LinearLayout>

这是日志猫

12-28 15:46:49.267 2751-2751/? I/art: Not late-enabling -Xcheck:jni (already on)
12-28 15:46:49.267 2751-2751/? W/art: Unexpected CPU variant for X86 using defaults: x86
12-28 15:46:49.326 2751-2751/com.example.utente.progettigscorsipa W/System: ClassLoader referenced unknown path: /data/app/com.example.utente.progettigscorsipa-2/lib/x86
12-28 15:46:49.332 2751-2751/com.example.utente.progettigscorsipa I/InstantRun: Instant Run Runtime started. Android package is com.example.utente.progettigscorsipa, real application class is null.
12-28 15:46:50.278 2751-2751/com.example.utente.progettigscorsipa W/System: ClassLoader referenced unknown path: /data/app/com.example.utente.progettigscorsipa-2/lib/x86
12-28 15:46:50.546 2751-2751/com.example.utente.progettigscorsipa W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
12-28 15:46:50.793 2751-2780/com.example.utente.progettigscorsipa I/OpenGLRenderer: Initialized EGL, version 1.4
12-28 15:46:50.793 2751-2780/com.example.utente.progettigscorsipa D/OpenGLRenderer: Swap behavior 1
12-28 15:46:50.948 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:46:50.948 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8e7ce4a0, error=EGL_BAD_MATCH
12-28 15:46:50.998 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:46:50.998 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8e7ce4e0, error=EGL_BAD_MATCH
12-28 15:49:16.811 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:49:16.811 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8edc9100, error=EGL_BAD_MATCH
12-28 15:49:19.918 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:49:19.918 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9ce3cae0, error=EGL_BAD_MATCH
12-28 15:49:19.993 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:49:19.993 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9b091060, error=EGL_BAD_MATCH
12-28 15:49:20.017 2751-2751/com.example.utente.progettigscorsipa I/Choreographer: Skipped 55 frames!  The application may be doing too much work on its main thread.
12-28 15:49:25.376 2751-2751/com.example.utente.progettigscorsipa I/Choreographer: Skipped 78 frames!  The application may be doing too much work on its main thread.
12-28 15:49:26.001 2751-2751/com.example.utente.progettigscorsipa I/Choreographer: Skipped 36 frames!  The application may be doing too much work on its main thread.
12-28 15:49:26.598 2751-2751/com.example.utente.progettigscorsipa I/Choreographer: Skipped 34 frames!  The application may be doing too much work on its main thread.
12-28 15:49:29.638 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:49:29.638 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9ce3cac0, error=EGL_BAD_MATCH
12-28 15:49:32.900 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:49:32.900 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9ce3cae0, error=EGL_BAD_MATCH
12-28 15:49:34.947 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:49:34.947 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8baf1c00, error=EGL_BAD_MATCH
12-28 15:49:35.386 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:49:35.386 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9ce3c380, error=EGL_BAD_MATCH
12-28 15:49:38.009 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:49:38.009 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8baf1c00, error=EGL_BAD_MATCH
12-28 15:49:40.678 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:49:40.678 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9ce3cae0, error=EGL_BAD_MATCH
12-28 15:49:43.712 2751-2780/com.example.utente.progettigscorsipa E/EGL_emulation: tid 2780: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
12-28 15:49:43.713 2751-2780/com.example.utente.progettigscorsipa W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8baf1c00, error=EGL_BAD_MATCH

推荐答案

我的问题解决了,是我手机的问题,内存不够

I solved my problem, it was a problem of my mobile, it didn't have enough memory

这篇关于Android:应用程序在模拟器上运行,但在我的手机上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆