0

I am making a listview with multiple sppech_recognizers inside its each row... in which that speech recognition result text will be stored inside the textview inside the listview:

Basic Model:

ListView -> { rows :: [ multiple speech recognizers ] }

public class ListAdapter extends ArrayAdapter<datamodel> implements RecognitionListener {

 public static class ViewHolderItems {
    AtomPayment datamodel;
    TextView total_hrs;
    TextView date;
    TextView Hour;
    TextView value;
    ToggleButton mic_for_hrs;
    ToggleButton mic_for_desc;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    row = convertView;
    ViewHolderItems holder = null;

    if (row == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(R.layout.list_row_addtime, parent, false);

        holder = new ViewHolderItems();
        holder.atomPayment = items.get(position);
        holder.mic_for_hrs = (ToggleButton) row.findViewById(R.id.MIC_hours);
        holder.mic_for_hrs.setTag(holder.atomPayment);
        speak_hours(holder, position);
        holder.mic_for_desc = (ToggleButton) row.findViewById(R.id.MIC_desc);
        holder.mic_for_desc.setTag(holder.atomPayment);

        holder.date = (TextView) row.findViewById(R.id.textview_date);
        setDateTextChangeListener(holder);
        holder.Hour = (EditText) row.findViewById(R.id.edit_hours_data);
        setHourTextChangeListener(holder);
        holder.value = (EditText) row.findViewById(R.id.edit_desc_data);
        setValueTextListeners(holder);

    } else {
        holder = (ViewHolderItems) row.getTag();
    }   

    row.setTag(holder);



    return row;
}

@Override
public void onResults(Bundle results) {
Log.i(LOG_TAG, "onResults 1");
        String text = "";
        Float valueof_text;
        Integer compare = 24;

        try {
            ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            text += matches.get(0);

            System.out.println("MAIN----------------->      " + matches);
            System.out.println("TAG----------------->      " + matches.get(0));

            valueof_text = Float.parseFloat(text);

            if (valueof_text.intValue() > compare.intValue()) {
                Toast.makeText(context, "Speak Again!!!", Toast.LENGTH_LONG).show();
            }
            else {
                holder.Hour.setText(text);
            }

        } catch (NumberFormatException number){
            number.getMessage(); number.printStackTrace();
        }  catch (NullPointerException number){
            number.getMessage(); number.printStackTrace();
        }
}

And from this i am getting this below result for this multiple sppech recognizer issue:

java.lang.NullPointerException at com.example.testing.ListAdapter.onResults(ListAdapter.java:429)
at android.speech.SpeechRecognizer$InternalListener$1.handleMessage(SpeechRecognizer.java:448)
at android.os.Handler.dispatchMessage(Handler.java:110)

I have get stucked here, any help would be completely appriciated... Thankyou in advance.

Panup Pong
  • 1,871
  • 2
  • 22
  • 44
amit pandya
  • 1,384
  • 13
  • 22
  • holder.Hour.setText(text); this one is line 429 – amit pandya Dec 09 '17 at 12:29
  • Although you can catch a NullPointerException, its not recommended. You should check by just an if statement, in this case : `if(holder != null) { holder.Hour.setText(text); }` - where are you assigning `holder`? Just put a break point in and see the initialisation state of your local and instance variables – Mark Dec 09 '17 at 12:51

0 Answers0