M
M
Mikhail2017-02-13 08:02:08
Android
Mikhail, 2017-02-13 08:02:08

Resources$NotFoundException: Resource ID #0x0. What could be wrong in the code?

public void startMicro(View view) {
        if (whatButton == 10) {
            isSpeechOn = false;
            whatButton = 0;
            MainButton.setImageResource(R.drawable.mainmicro);
            isrunning = false;
            recognizer.finishRecording();
        } else {
            if (whatButton == 1) {
                seconds = 0;
                seconds = 0;
                myseconds = 0;
                if (view.getId() == R.id.mainbtn) {
                    TextView result = (TextView) findViewById(R.id.resultText);
                    MainButton.setImageResource(R.drawable.stop);
                    startRec();
                }
            }
        }
    }

@TargetApi(Build.VERSION_CODES.M)
    public void startRec() {
        final Context context = getApplicationContext();
        if (context == null) {
            return;
        }
        if (ContextCompat.checkSelfPermission(context, RECORD_AUDIO) != PERMISSION_GRANTED) {
            requestPermissions(new String[]{RECORD_AUDIO}, 1);
        } else {
            resetRecognizer();
            recognizer = Recognizer.create(Recognizer.Language.RUSSIAN, Recognizer.Model.NOTES, reclistener, true);
            recognizer.start();
        }
    }

In the error, these lines point to my code:
at com.govorillo.youtube.govorilka.MainActivity.startRec(MainActivity.java:218)
at com.govorillo.youtube.govorilka.MainActivity.startMicro(MainActivity.java:195)

What could be the problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
coden55, 2017-02-13
@coden55

IDE in editor not highlighting error? Try rebuild project

A
Agrass, 2017-02-13
@Agrass

In fact, when building an application, R.class is generated. I had such a problem, first of all I recommend checking whether you have all the sizes of the required images (mdpi-drawable, hdpi-drawable, xhdpi-drawable, etc.), and how suggested by coden55 to do a Project Rebuild. R.class will be regenerated and the error should be gone. Before rolling out to production, I recommend doing a rebuild every time.

D
DanilinEgor, 2017-02-14
@DanilinEgor

Faced such an error with typos like textView.setText(0). Or textView.setText(x), and xcould be equal to 0. Perhaps you have something like this in your code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question