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 7806409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:31:33+00:00 2026-06-02T02:31:33+00:00

I have made an android app which uses speech recognition. The problem is that

  • 0

I have made an android app which uses speech recognition. The problem is that it shows nullpointerexception.

The code which shows the error is :

public void startVoiceRecognitionActivity()
{
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Give Me An Order!");
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
 * Handle the results from the recognition activity.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
        //store the result that the user might have said but google thinks he has said that only
        ArrayList<String> r=data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        String[] result = new String[r.size()];
        result = r.toArray(result);
        Intent i=new Intent(getApplicationContext(),search.class);
        if(result[0].length()<=0)
        {
            showToast("Could not fetch command properly try again");
        }
        else
        {
            i.putExtra("q", result[0]);
            startActivity(i);
        }
    }

    super.onActivityResult(requestCode, resultCode, data);
}

the error is occurring on the line if(result[0].length()<=0)

  • 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-02T02:31:35+00:00Added an answer on June 2, 2026 at 2:31 am

    Taken from the documentation of <T> T[] toArray(T[] a):

    If the list fits in the specified array with room to spare (i.e., the
    array has more elements than the list), the element in the array
    immediately following the end of the list is set to null.

    Thus if your r variable points to empty list the first element of your array will be null. This is causing your NPE. You can try verifying the size of the list, but it is most certainly the case.

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

Sidebar

Related Questions

I have an Android app project that contains all of my code. I've made
I have made an android app which working fine. I implemented the Login functionality
I have Ripple which im using to test app made for android. App is
I have made an android app which working fine. I implemented the Login functionality
I have an app on the Android Market that's throwing an exception which I've
I have made an app that starts a service, which starts a timer, which
I have an Android app which uses an SSLSocketFactory to load a pkcs12 certificate
I am working on an Android app that uses the gdata-java-client to download documents
I am trying to create a simple 3-D app for android that will have
I have published an app which is at version 3.0. I have made some

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.