It works on avd, but if you connect to the air meter and press the Radio button, the app is forced to end

Asked 2 years ago, Updated 2 years ago, 113 views

2022-03-13 18:18:27.081 22531-22531/com.example.plausibleapp E/Zygote: v2

2022-03-13 18:18:27.086 22531-22531/com.example.plausibleapp E/Zygote: accessInfo : 0

2022-03-13 18:19:38.291 22531-22531/com.example.plausibleapp E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.example.plausibleapp, PID: 22531


android.content.res.Resources$NotFoundException: Resource ID #0x7f070056


    at android.content.res.Resources.getValue(Resources.java:2558)


    at androidx.appcompat.widget.ResourceManagerInternal.loadDrawableFromDelegates(ResourceManagerInternal.java:256)


    at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:143)


    at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:136)


    at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:66)


    at androidx.appcompat.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:91)


    at androidx.appcompat.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:102)


    at com.example.plausibleapp.MainActivity$3.onCheckedChanged(MainActivity.java:67)


    at android.widget.RadioGroup.setCheckedId(RadioGroup.java:173)


    at android.widget.RadioGroup.access$600(RadioGroup.java:53)


    at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:351)


    at android.widget.CompoundButton.setChecked(CompoundButton.java:168)


    at android.widget.CompoundButton.toggle(CompoundButton.java:118)


    at android.widget.RadioButton.toggle(RadioButton.java:76)


    at android.widget.CompoundButton.performClick(CompoundButton.java:123)


    at android.view.View$PerformClick.run(View.java:22526)


    at android.os.Handler.handleCallback(Handler.java:739)


    at android.os.Handler.dispatchMessage(Handler.java:95)


    at android.os.Looper.loop(Looper.java:158)


    at android.app.ActivityThread.main(ActivityThread.java:7225)


    at java.lang.reflect.Method.invoke(Native Method)


    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)


    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

If you check with AVD, the internet is too slow to check.

If you connect it to your phone and check it, the moment you click Radio Button, the logcat pops up and the app is forced to shut down on your phone.

I googled and looked it up, but I couldn't find a solution, so I'm asking

Please<

android android-studio logcat force-quit

2022-09-20 11:04

2 Answers

       rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(RadioGroup radioGroup, int i) {
               RadioButton select = (RadioButton) findViewById(i);
               switch((String)select.getText()){
                   case "11.0(R)":
                       i1.setImageResource(R.drawable.ad);
                       break;
                   case "12.0(S)":
                       i1.setImageResource(R.drawable.ad2);
                       break;
               }
           }
       });

You're going to die here on setImageResource. There seems to be something wrong with the resource R.drawable.ad or R.drawable.ad2.


2022-09-20 11:04

package com.example.plausibleapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    Button button1,button2;
    EditText ed1;
    RadioButton rb1,rb2;
    RadioGroup rg1;
    ImageView i1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        i1 = (ImageView) findViewById(R.id.i1);

        button1 = (Button) findViewById(R.id.button1);
        button2 = (Button) findViewById(R.id.button2);

        ed1 = (EditText) findViewById(R.id.textView);

        rg1 = (RadioGroup) findViewById(R.id.rg1);

        rb1 = (RadioButton) findViewById(R.id.RButton1);
        rb2 = (RadioButton) findViewById(R.id.RButton2);

        button1.setBackgroundColor(Color.GRAY);
        button2.setBackgroundColor(Color.GRAY);

        button1.setTextColor(Color.BLACK);
        button2.setTextColor(Color.BLACK);

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getApplicationContext(),ed1.getText(),Toast.LENGTH_SHORT).show();
            }
        });
        button2.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                Toast.makeText(getApplicationContext(), "Go to the Internet," Toast.LENGTH_SHORT).show();
                Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"+ed1.getText()));
                startActivity(mIntent);
            }
        });
       rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(RadioGroup radioGroup, int i) {
               RadioButton select = (RadioButton) findViewById(i);
               switch((String)select.getText()){
                   case "11.0(R)":
                       i1.setImageResource(R.drawable.ad);
                       break;
                   case "12.0(S)":
                       i1.setImageResource(R.drawable.ad2);
                       break;
               }
           }
       });
    }
}


2022-09-20 11:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.