Android:应用程序在模拟器上运行,但在我的手机上崩溃

2024-02-21

我的应用程序在模拟器 Nexus 5(Android 7.0,API 24)上运行,但当我尝试使用“onClick”打开另一个活动时,它在我的手机(Samsung J5 Android 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>

这是前一个活动因崩溃而无法打开的活动之一

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

将您的 Android SDK 更新为您的 Android 手机的版本,并在 build.gradle 文件中定义您的手机的最小和最大 sdk 版本。

android {
 ...
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 24
}
productFlavors {
  main {
  ...
 }
 afterLollipop {
   ...
  minSdkVersion 21
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android:应用程序在模拟器上运行,但在我的手机上崩溃 的相关文章

随机推荐

  • 如何使用 swift 4 解析 JSON

    我对获取水果的细节感到困惑 fruits id 1 image https cdn1 medicalnewstoday com content images headlines 271 271157 bananas jpg name Ban
  • 是否可以在没有 Visual Studio 的情况下安装 C# 编译器?

    我想从命令行构建项目 是否可以在不安装的情况下部署 C 编译器视觉工作室 http en wikipedia org wiki Microsoft Visual Studio 当然 该框架包含一个编译器 csc exe 看着本文 https
  • 两个ExecutorService可以共享一个线程池吗?

    我有一个记录集合要处理 并且处理可以并行化 所以我创建了一个执行服务 http java sun com j2se 1 5 0 docs api java util concurrent ExecutorService html via 执
  • 无法使用 Safari 连接到 AWS Cloud9 IDE

    我正在尝试使用 Cloud 9 但在 IDE 部署过程中不断收到以下消息 Your web browser does not have third party cookies enabled 我使用的是 Safari 11 0 3 在首选项
  • 为什么替代模式中不允许使用变量?

    通常 您有 对称 匹配 并且想要编写如下内容 def g p Int Int p match case 10 n n 10 gt println n case gt println nope 这是不允许的 但如果每个替代方案都有相同的变量
  • C++ 名称解析(和重载)规则列表

    在哪里我可以找到 C 兼容编译器必须应用才能执行的规则列表名称解析 包括超载 我想要一些自然语言算法或流程图之类的东西 C 标准当然有这套规则 但它是随着新语言语句的引入而建立的 结果很难记住 长话短说 我想知道这个问题的完整而详细的答案
  • 基于 F1 的自定义评估函数,用于 xgboost - Python API

    我编写了以下自定义评估函数与 xgboost 一起使用 以优化 F1 不幸的是 当使用 xgboost 运行时它会返回异常 评价函数如下 def F1 eval preds labels t np arange 0 1 0 005 f np
  • 让菱形方形分形算法变得无穷大

    我正在尝试生成一个无限的地图 我在 Python 中执行此操作 但无法让噪声库正常工作 它们似乎从未找到我的 VS2010 并且在原始 Python 中执行此操作会太慢 因此 我正在尝试使用菱形平方算法 http en wikipedia
  • React Native 的异步存储安全吗?

    我想将敏感数据本地存储在 React Native 应用程序中 数据只能供编写它的应用程序使用吗 AsyncStorage不适合存储敏感信息 您可能会发现这很有用 https github com oblador react native
  • 将事件从自定义控件传播到表单

    我有一个自定义控件 例如 public sealed class BorderEx Control public static readonly RoutedEvent ReloadClickEvent EventManager Regis
  • 如何通过扫描码(不是虚拟键码)获取按键状态?

    无论如何 是否可以仅使用扫描码来获取键盘按键的状态 向下还是向上 我在 win32 中找不到任何此功能 有人知道有什么方法可以实现这一目标吗 附注我需要键盘的实际状态 而不是从 Windows 消息 如 GetKeyState 返回 派生的
  • 检查用户是否完成了连续 UISlider 上的滑动?

    在我的应用程序中 我有几个 UISlider 实例来更改各种值 这些值显示在滑块旁边 并在应用程序的另一个可见部分的 3D 空间中呈现 3D 部分包括一些相当繁重的计算 目前似乎不可能随着滑块的变化实时更新它 这意味着我必须设置滑块的con
  • 如何在SQL表中插入空行? [复制]

    这个问题在这里已经有答案了 可能的重复 将行插入仅包含一个 IDENTITY 列的表中 https stackoverflow com questions 4117676 inserting rows into a table with o
  • 如何在遇到第一个错误时取消 dockerfile 映像构建?

    如果我的 dockerfile 中的 RUN 命令出现错误 它只会继续执行下一个命令 您确定该命令确实返回错误吗 以下 Dockerfile 无法访问echo foo FROM alpine RUN false RUN echo foo 它
  • 像这样从另一个线程发送电子邮件可以吗?

    在网站中 有时发送电子邮件需要几秒钟 所以我需要从另一个线程发送电子邮件 不要等到电子邮件发送 我找到了这个answer https stackoverflow com questions 57845 backgroundworker th
  • 为什么我无法克隆 git 存储库以用于 readthedocs 来构建文档?

    我正在尝试导入我的项目代码readthedocs这样它就可以为我生成文档 然而 在克隆存储库的阶段 已经出现错误 checkout Failed to import project skipping build Error Failed t
  • 值、类型、种类……作为无限序列?

    我才刚刚开始熟悉类型的概念 所以如果我没有很好地表达我的问题 请耐心等待 值有类型 3 Int 1 2 3 Int c True Char Bool 类型有种类 the type Int has kind the type Int also
  • 核心数据模型设计 - 更改“活动”对象也会更改已保存的对象

    我正在开发我的第一个 Core Data 项目 在 iPhone 上 并且我真的很喜欢它 核心数据是很酷的东西 然而 我遇到了一个设计困难 我不确定如何解决 尽管我认为这是一个相当常见的情况 它涉及数据模型 为了清楚起见 我将使用一个想象的
  • 循环播放列表中的声音

    我得到了这个带有 2 个声音的列表 我想用这个代码来播放它们 不幸的是 它只播放列表中的最后一个声音 我知道使用 pygame Sound 是一个解决方案 但我不知道如何使用它 array a mp3 b mp3 for i in rang
  • Android:应用程序在模拟器上运行,但在我的手机上崩溃

    我的应用程序在模拟器 Nexus 5 Android 7 0 API 24 上运行 但当我尝试使用 onClick 打开另一个活动时 它在我的手机 Samsung J5 Android 5 1 1 上的精确活动中崩溃 这是崩溃的活动 pub