Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8452315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:28:05+00:00 2026-06-10T11:28:05+00:00

I have two buttons with in the same activity. Each buttons calls the recognizerIntent

  • 0

I have two buttons with in the same activity. Each buttons calls the recognizerIntent to do some speech recognition. What Im trying to accomplish if have the microphone Icons Image1 and Image2 be made invisible or gone if the correct word is spoken.

public class Cooking  extends Activity implements OnClickListener{


    ListView lv;
    static final int check = 1;
    static final int checka = 2;


    int counter_score;
     int counter_score_b;
    TextView txView;
    MediaPlayer ourSong;
    ImageView display,image1,image2;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        counter_score=0;
        counter_score_b=0;
        setContentView(R.layout.cooking);
        ImageView image1 = (ImageView) findViewById(R.id.image_1_wrong);
        ImageView image2 = (ImageView) findViewById(R.id.image_2_wrong);        
        initialize();





}


private void initialize() {
    // TODO Auto-generated method stub
    lv = (ListView)findViewById(R.id.lvVoiceReturn);
    txView = (TextView)findViewById(R.id.counter);

    ImageView image1 = (ImageView) findViewById(R.id.image_1_wrong);
    ImageView image2 = (ImageView) findViewById(R.id.image_2_wrong);

    image1.setOnClickListener(this);
    image2.setOnClickListener(this);


    ActionBar actionBar = getActionBar();
     actionBar.setDisplayHomeAsUpEnabled(false);

}




    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.IVimage_1_wrong){
        Intent a = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        a.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        a.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
        a.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak");
        startActivityForResult(a, checka);
    }else if(v.getId() == R.id.IVimage_2_wrong){
        Intent b = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        b.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        b.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
        b.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak.");
        startActivityForResult(b, checkb);
    }
}


 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        if (requestCode == checka && resultCode == RESULT_OK){
            ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, results));
            if(results.contains("cooking")|| results.contains("yes really") || results.contains("disease")){

                counter_score ++;
                    ///////I though this would make ImageView Image1 not be visible  
                image1.setVisibility(View.GONE);}
                ourSong = MediaPlayer.create(Cooking.this, R.raw.rightsound2);
                ourSong.start();
                AlertDialog dialogBuilder = new AlertDialog.Builder(this).create();
                dialogBuilder.setTitle("Good");dialogBuilder.setMessage("Correct");
                dialogBuilder.setIcon(R.drawable.ic_mark);
                dialogBuilder.show();
                Thread timer = new Thread(){
                    public void run(){
                        try{
                         sleep(2500);
                        }catch (InterruptedException e){
                            e.printStackTrace();
                        } finally {





                        }
                    }
                };
                timer.start();

            }else{

                lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, results));
                counter_score +=0;

                counter_score_z +=0;
                ourSong = MediaPlayer.create(Cooking.this, R.raw.wrongsound);
                ourSong.start();
                AlertDialog dialogBuilder = new AlertDialog.Builder(this).create();
                dialogBuilder.setTitle("Oops");
                dialogBuilder.setMessage("Error msg");
                dialogBuilder.setIcon(R.drawable.ic_wrong);
                dialogBuilder.setButton("Continue", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {


                        Intent openMovilTeacherApp = new Intent(Cooking.this, LetterEx.class);
                        startActivity(openMovilTeacherApp);
                        finish();
                    }
                });
                dialogBuilder.setButton2("Try again", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        dialog.dismiss();
                    }
                });
                dialogBuilder.show();
                Thread timer = new Thread(){
                    public void run(){
                        try{
                         sleep(4000);
                        }catch (InterruptedException e){
                            e.printStackTrace();
                        } finally {



                        }
                    }
                };
                timer.start();
            }



        }
        //////Delivering MAIL/////
        if (requestCode == checkb && resultCode == RESULT_OK){
            ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, results));
            if(results.contains("delivering mail")|| results.contains("no not really") || results.contains("disease")){

                counter_score ++ ;
                 ///////// the next line was supposed to make the image2 no be visible, or gone
                image2.setVisibility(View.GONE);}
                counter_score_z +=1;
                ourSong = MediaPlayer.create(Cooking.this, R.raw.rightsound2);
                ourSong.start();
                AlertDialog dialogBuilder = new AlertDialog.Builder(this).create();
                dialogBuilder.setTitle("Good");dialogBuilder.setMessage("Correct");
                dialogBuilder.setIcon(R.drawable.ic_mark);
                dialogBuilder.show();
                Thread timer = new Thread(){
                    public void run(){
                        try{
                         sleep(2500);
                        }catch (InterruptedException e){
                            e.printStackTrace();
                        } finally {
                            Intent nextAct2 = new Intent(Cooking.this, LetterEx.class);
                            startActivity(nextAct2);
                            finish();



                        }
                    }
                };
                timer.start();

            }else{

                lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, results));
                counter_score +=0;
                txView.setId(0);
                counter_score_z +=0;
                ourSong = MediaPlayer.create(Cooking.this, R.raw.wrongsound);
                ourSong.start();
                AlertDialog dialogBuilder = new AlertDialog.Builder(this).create();
                dialogBuilder.setTitle("Oops,");
                dialogBuilder.setMessage("Error Msg");
                dialogBuilder.setIcon(R.drawable.ic_wrong);
                dialogBuilder.setButton("Continuar", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {


                        Intent openMovilTeacherApp = new Intent(Cooking.this, LetterEx.class);
                        startActivity(openMovilTeacherApp);
                        finish();
                    }
                });
                dialogBuilder.setButton2("Try again", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        dialog.dismiss();
                    }
                });
                dialogBuilder.show();
                Thread timer = new Thread(){
                    public void run(){
                        try{
                         sleep(4000);
                        }catch (InterruptedException e){
                            e.printStackTrace();
                        } finally {



                        }
                    }
                };
                timer.start();
            }



        }



        super.onActivityResult(requestCode, resultCode, data);



    }

}

My cooking.xml

<ImageView android:src="@drawable/small_right_blue_mic"
        android:id="@+id/image_1_wrong" 
       android:layout_width="68dp"
        android:layout_height="68dp"
        android:layout_marginLeft="-150dp"
        android:layout_marginTop="15dp"
        android:visibility="invisible"/>

     <ImageView android:src="@drawable/small_right_blue_mic"
        android:id="@+id/image_2_wrong" 
       android:layout_width="52dp"
        android:layout_height="59dp"
        android:layout_marginLeft="-0dp"
        android:layout_marginTop="25dp"
        android:visibility="visible"/>

Error log

08-29 17:15:54.600: E/AndroidRuntime(1953): FATAL EXCEPTION: main
08-29 17:15:54.600: E/AndroidRuntime(1953): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=222, result=-1, data=Intent { (has extras) }} to activity {com.testapp.app/com.testapp.app.Cooking}: java.lang.NullPointerException
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:28:06+00:00Added an answer on June 10, 2026 at 11:28 am

    Your problem is you defined image1 and image2 locally. Change it like this. And you need to use findviewbyid() once only. thats enought

    public class Cooking  extends Activity implements OnClickListener{
    
    
        ListView lv;
        static final int check = 1;
        static final int checka = 2;
    
    
        int counter_score;
         int counter_score_b;
        TextView txView;
        MediaPlayer ourSong;
        ImageView display,image1,image2;
    
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            counter_score=0;
            counter_score_b=0;
            setContentView(R.layout.cooking);
            image1 = (ImageView) findViewById(R.id.image_1_wrong);
            image2 = (ImageView) findViewById(R.id.image_2_wrong);        
            initialize();
    
    
    
    
    
    }
    
    
    private void initialize() {
        // TODO Auto-generated method stub
        lv = (ListView)findViewById(R.id.lvVoiceReturn);
        txView = (TextView)findViewById(R.id.counter);
    
    
        image1.setOnClickListener(this);
        image2.setOnClickListener(this);
    
    
        ActionBar actionBar = getActionBar();
         actionBar.setDisplayHomeAsUpEnabled(false);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two buttons with the same ID: <button type=submit onclick=//do something id=theID>button 1</button>
I have two buttons in my flex app next to each other, ButtonA and
I have form with two buttons having same name but different values ,how to
I have an activity with two Buttons and a TextView in a LinearLayout. My
i have two sub activities apart from main activity. The sequence of calls go
I have an activity on the top of it there are some buttons from
I want to have two button in the same size one in the left
I have two buttons that moves a movieclip up/down the Y-axis. How do I
I have two buttons, one for start recording and another for stop recording. i
I have two buttons, which the user can click and will open a FileDiagloag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.