当我打开第四个活动时,我的应用程序下降了

Posted

技术标签:

【中文标题】当我打开第四个活动时,我的应用程序下降了【英文标题】:my application fall as i open the fourth activitity 【发布时间】:2018-06-14 02:17:56 【问题描述】:

我试图自己解决它,但我疯了,因为我不明白为什么它不起作用。

我开发了一个非常简单的应用程序,用户需要回答大约 10 个问题,程序接受输入来计算它并返回他输入的推荐。

它从一个活动传递到另一个活动(答案保存在 XML 文件中),第四个活动将所有答案转换为 java,在这个 java 文件中,我进行计算。

但是当我从一个活动传递到另一个活动时,一切正常,直到最后一个活动跨越任何时候,我什至没有开始计算。 在转换步骤中,我做了模拟器,并且在它倒下的任何时候。 我试图删除 RadioButton 转换,它工作正常,但据我所知,我将 RadioButton 转换得很好。

我的 javaFile 代码(最后一个活动):

    protected void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_last);


        //declare RadioGroup
        sort_b_r_g=(RadioGroup) findViewById(R.id.sort_b_r_g);
        winter_r_g=(RadioGroup) findViewById(R.id.winter_r_g);
        stand_r_g=(RadioGroup) findViewById(R.id.stand_r_g);
        corner_r_g=(RadioGroup) findViewById(R.id.corner_r_g);
        sex_r_g=(RadioGroup) findViewById(R.id.sex_r_g);

        //declare RadioButton.... the problem is here.

        sort_b_r_b=(RadioButton) findViewById(sort_b_r_g.getCheckedRadioButtonId());
        winter_r_b=(RadioButton) findViewById(winter_r_g.getCheckedRadioButtonId());
        stand_r_b=(RadioButton) findViewById(stand_r_g.getCheckedRadioButtonId());
        corner_r_b=(RadioButton) findViewById(corner_r_g.getCheckedRadioButtonId());
        sex_r_b=(RadioButton) findViewById(sex_r_g.getCheckedRadioButtonId());



非常感谢帮手:)!

关于响应者,应用程序刚刚落下。 错误: “应用程序名称已停止。 再次打开应用”

logcat 错误:

01-05 07:47:42.389 5213-5213/? I/zygote: Not late-enabling -Xcheck:jni (already on)
01-05 07:47:42.425 5213-5213/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
01-05 07:47:42.840 5213-5213/com.example.yagel.twoactivity I/InstantRun: starting instant run server: is main process
01-05 07:47:43.572 5213-5239/com.example.yagel.twoactivity D/OpenGLRenderer: HWUI GL Pipeline

                                                                             [ 01-05 07:47:43.641  5213: 5239 D/         ]
                                                                             HostConnection::get() New Host Connection established 0x966c00c0, tid 5239
01-05 07:47:43.650 5213-5239/com.example.yagel.twoactivity I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
01-05 07:47:43.650 5213-5239/com.example.yagel.twoactivity I/OpenGLRenderer: Initialized EGL, version 1.4
01-05 07:47:43.650 5213-5239/com.example.yagel.twoactivity D/OpenGLRenderer: Swap behavior 1
01-05 07:47:43.651 5213-5239/com.example.yagel.twoactivity W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
01-05 07:47:43.651 5213-5239/com.example.yagel.twoactivity D/OpenGLRenderer: Swap behavior 0
01-05 07:47:43.666 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglCreateContext: 0xa9d852a0: maj 2 min 0 rcv 2
01-05 07:47:43.704 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:47:43.847 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:47:49.596 5213-5218/com.example.yagel.twoactivity I/zygote: Do partial code cache collection, code=29KB, data=30KB
01-05 07:47:49.600 5213-5218/com.example.yagel.twoactivity I/zygote: After code cache collection, code=29KB, data=30KB
01-05 07:47:49.600 5213-5218/com.example.yagel.twoactivity I/zygote: Increasing code cache capacity to 128KB
01-05 07:47:49.722 5213-5218/com.example.yagel.twoactivity I/zygote: Do partial code cache collection, code=29KB, data=51KB
01-05 07:47:49.723 5213-5218/com.example.yagel.twoactivity I/zygote: After code cache collection, code=29KB, data=51KB
01-05 07:47:49.723 5213-5218/com.example.yagel.twoactivity I/zygote: Increasing code cache capacity to 256KB
01-05 07:47:49.723 5213-5218/com.example.yagel.twoactivity I/zygote: JIT allocated 71KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
01-05 07:47:49.723 5213-5218/com.example.yagel.twoactivity I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
01-05 07:47:49.797 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:47:49.812 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:47:49.832 5213-5218/com.example.yagel.twoactivity I/zygote: Do full code cache collection, code=110KB, data=63KB
01-05 07:47:49.832 5213-5218/com.example.yagel.twoactivity I/zygote: After code cache collection, code=91KB, data=44KB
01-05 07:47:50.062 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:47:50.159 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:47:50.236 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:47:50.316 5213-5213/com.example.yagel.twoactivity V/View: dispatchProvideAutofillStructure(): not laid out, ignoring 0 children of 1073741851
01-05 07:47:50.329 5213-5213/com.example.yagel.twoactivity I/AssistStructure: Flattened final assist data: 8332 bytes, containing 1 windows, 29 views
01-05 07:47:53.936 5213-5218/com.example.yagel.twoactivity I/zygote: Do partial code cache collection, code=123KB, data=78KB
01-05 07:47:53.940 5213-5218/com.example.yagel.twoactivity I/zygote: After code cache collection, code=123KB, data=78KB
01-05 07:47:53.940 5213-5218/com.example.yagel.twoactivity I/zygote: Increasing code cache capacity to 512KB
01-05 07:48:03.404 5213-5218/com.example.yagel.twoactivity I/zygote: Do full code cache collection, code=248KB, data=171KB
01-05 07:48:03.413 5213-5218/com.example.yagel.twoactivity I/zygote: After code cache collection, code=245KB, data=131KB
01-05 07:48:03.517 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:48:03.575 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:48:03.685 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:48:03.742 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:48:03.787 5213-5213/com.example.yagel.twoactivity V/View: dispatchProvideAutofillStructure(): not laid out, ignoring 0 children of 1073741840
01-05 07:48:03.793 5213-5213/com.example.yagel.twoactivity I/AssistStructure: Flattened final assist data: 5020 bytes, containing 1 windows, 18 views
01-05 07:48:03.829 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:48:04.169 5213-5239/com.example.yagel.twoactivity D/EGL_emulation: eglMakeCurrent: 0xa9d852a0: ver 2 0 (tinfo 0xa9d83280)
01-05 07:48:04.893 5213-5218/com.example.yagel.twoactivity I/zygote: Do partial code cache collection, code=247KB, data=147KB
01-05 07:48:04.893 5213-5218/com.example.yagel.twoactivity I/zygote: After code cache collection, code=247KB, data=147KB
01-05 07:48:04.893 5213-5218/com.example.yagel.twoactivity I/zygote: Increasing code cache capacity to 1024KB
01-05 07:48:26.207 5213-5213/com.example.yagel.twoactivity D/AndroidRuntime: Shutting down VM
01-05 07:48:26.208 5213-5213/com.example.yagel.twoactivity E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.example.yagel.twoactivity, PID: 5213
                                                                             java.lang.RuntimeException: Unable to start activity ComponentInfocom.example.yagel.twoactivity/com.example.yagel.twoactivity.Last: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.RadioGroup.getCheckedRadioButtonId()' on a null object reference
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                                                                                 at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                 at android.os.Looper.loop(Looper.java:164)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:6494)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
                                                                              Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.RadioGroup.getCheckedRadioButtonId()' on a null object reference
                                                                                 at com.example.yagel.twoactivity.Last.onCreate(Last.java:42)
                                                                                 at android.app.Activity.performCreate(Activity.java:6999)
                                                                                 at android.app.Activity.performCreate(Activity.java:6990)
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
                                                                                 at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                 at android.os.Looper.loop(Looper.java:164) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:6494) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_
    android:layout_
    tools:context="com.example.yagel.twoactivity.Last">

    <ImageView
        android:id="@+id/soft_im"
        android:layout_
        android:layout_
        android:layout_marginTop="50dp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/soft" />

    <ImageView
        android:id="@+id/long_im"
        android:layout_
        android:layout_
        android:layout_marginTop="50dp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/long_b" />

    <ImageView
        android:id="@+id/fish_im"
        android:layout_
        android:layout_
        android:layout_marginTop="50dp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/fish" />

    <ImageView
        android:id="@+id/short_im"
        android:layout_
        android:layout_
        android:layout_marginTop="50dp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/short_b" />

    <TextView
        android:id="@+id/ans"
        android:layout_
        android:layout_
        android:layout_marginBottom="140dp"
        android:text="כנראה שלא מלאת את כל הפרטים.\nיש לחזור על התהליך ולמלא את כל הפרטים"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>

找到解决方案后编辑 好的,所以我在父母身上发现了我的问题 R.id.id_name 在应用意图指向另一个项目时变为空。

所以,当我试图在第二个活动(从第四个)中对某个变量下达命令时,应用程序从中得到了一个空值。

所以解决方案是通过使变量“public static”表示 R.id.id_name 中的信息(例如我有 TextView“id_name”,所以在第二个活动中我初始化 String name_s 并做了 name_s=id_name。 gettext() 那么变量在打开新活动时没有改变..)

该应用程序运行良好,如果您有其他技术比我的更好,我会很高兴听到它,非常感谢帮助者:)

【问题讨论】:

您收到什么错误消息? 请发布您的 logcat 错误 发布 Logcat 和您的 XML 布局代码。 我在最后一行添加了错误的图像 张贴logcatrun 在那里你可以强制关闭 【参考方案1】:

这只是另一个 NullPointerException。您在 null 上使用 getCheckedRadioButtonId()。修复它,它会工作。记录您的代码并检查为什么您的单选按钮为空。

【讨论】:

对不起,但我试图找到那个为空的 RadioGroup 并且没有找到。我什至做了一个 if(RadioGroupx==null) Toast...“radioGroupx is null”但它仍然属于 NullPointerException... 某人的借口?帮助... 你可以上传你的项目,我会下载并尝试修复它

以上是关于当我打开第四个活动时,我的应用程序下降了的主要内容,如果未能解决你的问题,请参考以下文章

在材料ui选项卡组件中将选项卡设置为活动

当我在真实设备中打开活动时应用程序崩溃

当我尝试实现滚动条时,我的应用程序崩溃了

方向改变后的第二次活动

为啥当我在 uiscrollview 顶部添加对象时,即使我将所有四个约束都设置为 0,对象也会下降一点?

谷歌活动链接可以打开应用吗?