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

  • Home
  • SEARCH
  • 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 8475925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:01:51+00:00 2026-06-10T18:01:51+00:00

I used voice recognition sample code from existing one.But this code not working in

  • 0

I used voice recognition sample code from existing one.But this code not working in my eclipse.I got following error in my logcat.But this code perfectly working in others.I refered so many tutorials but i can’t clear where i put mistake?

Mycode:

public class MainActivity extends Activity {
     private static final int REQUEST_CODE = 1234;
        private ListView wordsList;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button speakButton = (Button) findViewById(R.id.speakButton);

        wordsList = (ListView) findViewById(R.id.list);

        // Disable button if no recognition service is present
        PackageManager pm = getPackageManager();
        List<ResolveInfo> activities = pm.queryIntentActivities(
                new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
        if (activities.size() == 0)
        {
            speakButton.setEnabled(false);
            speakButton.setText("Recognizer not present");
        }
    }

    /**
     * Handle the action of the button being clicked
     */
    public void speakButtonClicked(View v)
    {
        startVoiceRecognitionActivity();
    }

    /**
     * Fire an intent to start the voice recognition activity.
     */
    private void startVoiceRecognitionActivity()
    {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
        startActivityForResult(intent, REQUEST_CODE);
    }

    /**
     * Handle the results from the voice recognition activity.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
        {
            // Populate the wordsList with the String values the recognition engine thought it heard
            ArrayList<String> matches = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
            wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                    matches));
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

Logcat:

09-01 23:29:39.441: E/AndroidRuntime(225): Uncaught handler: thread main exiting due to uncaught exception
09-01 23:29:39.580: E/AndroidRuntime(225): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.voicerecog/com.example.voicerecog.MainActivity}: java.lang.NullPointerException
09-01 23:29:39.580: E/AndroidRuntime(225):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
09-01 23:29:39.580: E/AndroidRuntime(225):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
09-01 23:29:39.580: E/AndroidRuntime(225):  at android.app.ActivityThread.access$2100(ActivityThread.java:116)
09-01 23:29:39.580: E/AndroidRuntime(225):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
09-01 23:29:39.580: E/AndroidRuntime(225):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-01 23:29:39.580: E/AndroidRuntime(225):  at android.os.Looper.loop(Looper.java:123)
09-01 23:29:39.580: E/AndroidRuntime(225):  at android.app.ActivityThread.main(ActivityThread.java:4203)
09-01 23:29:39.580: E/AndroidRuntime(225):  at java.lang.reflect.Method.invokeNative(Native Method)
09-01 23:29:39.580: E/AndroidRuntime(225):  at java.lang.reflect.Method.invoke(Method.java:521)
09-01 23:29:39.580: E/AndroidRuntime(225):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
09-01 23:29:39.580: E/AndroidRuntime(225):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
09-01 23:29:39.580: E/AndroidRuntime(225):  at dalvik.system.NativeStart.main(Native Method)
09-01 23:29:39.580: E/AndroidRuntime(225): Caused by: java.lang.NullPointerException
09-01 23:29:39.580: E/AndroidRuntime(225):  at com.example.voicerecog.MainActivity.onCreate(MainActivity.java:38)
09-01 23:29:39.580: E/AndroidRuntime(225):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
09-01 23:29:39.580: E/AndroidRuntime(225):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
09-01 23:29:39.580: E/AndroidRuntime(225):  ... 11 more
  • 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-10T18:01:53+00:00Added an answer on June 10, 2026 at 6:01 pm

    Do check if R.id.speakButton is present in the layout activity_main.xml. If it is not present findviewbyid returns null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have downloaded the sample code GLPaint from developer.Apple website to draw pictures on
For everyone using Android's voice recognition API , there used to be a handy
i have used an avaudiorecoder to record user's voice. it records it but when
I've used following code as base to create a recorder. I can start and
Used code I found on SO to use the COM based Acrobat Reader to
I used Jquery to insert a variable to div. Please check my code. var
I am trying to return all MSFT Lync Users who have used voice conferencing
Is there end-to-end voice encryption in GSM ? If not, is voice communication between
The story: I'm writing a music player controlled by voice. Previously the project used
I realize that they are different beast used to solve different problems, but I

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.