Java Android:应用程序在emulator上运行,但在我的手机上崩溃

Java Android:应用程序在emulator上运行,但在我的手机上崩溃,java,android,android-studio,crash,Java,Android,Android Studio,Crash,我的应用程序在模拟器Nexus5(安卓7.0,API 24)上运行,但当我试图用“onClick”打开另一个活动时,它在我的手机(三星J5安卓5.1.1)上崩溃 这是崩溃的活动 public class CuboActivity extends AppCompatActivity { /** * The {@link android.support.v4.view.PagerAdapter} that will provide * fragments for each

我的应用程序在模拟器Nexus5(安卓7.0,API 24)上运行,但当我试图用“onClick”打开另一个活动时,它在我的手机(三星J5安卓5.1.1)上崩溃

这是崩溃的活动

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>
这是它的布局

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

将Android SDK更新为Android手机版本,并在build.gradle文件中定义手机的最低和最高SDK版本

android {
 ...
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 24
}
productFlavors {
  main {
  ...
 }
 afterLollipop {
   ...
  minSdkVersion 21
}
}
}

我解决了我的问题,那是我的手机的问题,它没有足够的内存

possst the logggggcatttt,你不认为我很快就喜欢aaa了吗zooombieee@PavneetSingh是Logcat事件日志吗?是的,@Pavneething我贴得好吗?@Curio你贴的日志不是我们要找的。在崩溃发生时,应该有一个清晰的Java异常堆栈跟踪。请编辑您的帖子并将其包括在内。@sunnythesine我是否必须将targetSDKversion更改为my mobile的版本?是的,您必须定义您的应用程序可以运行的最低版本。根据你的帖子,你的模拟器是Nexus 5(安卓7.0,API 24)和你的手机(三星J5安卓5.1.1)都有不同的API版本。现在是15,我有一个mobile 20 sdk,我是否将15更改为20?因此,最小值应为15,最大值应为API级别25,并且根据您的logcat日志,当您在手机上运行应用程序时,该应用程序的目录丢失。请检查权限和存储空间。那么我是否必须释放手机上的空间?
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
android {
 ...
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 24
}
productFlavors {
  main {
  ...
 }
 afterLollipop {
   ...
  minSdkVersion 21
}
}
}