java - Error in RESULT_OK on Public void onActivityResult -


i have code on mainactivity, when tried @ fragment homefragment i`ve got error @ result_ok @ public void onactivityresult.

i dont know whats wrong this, knows this? anyway here`s code:

package com.thesis.artificialintelligence;   import android.app.activity; import android.content.activitynotfoundexception; import android.content.componentname; import android.content.intent; import android.media.audiomanager; import android.os.bundle; import android.speech.recognizerintent; import android.speech.tts.texttospeech; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.button; import android.widget.textview; import java.util.arraylist; import java.util.calendar; import java.util.gregoriancalendar; import java.util.hashmap; import java.util.locale; import java.util.random; import javax.xml.transform.result;   public class homefragment extends fragment {     private textview resulttext; private textview resulttext2; private button button; texttospeech t1;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      t1 = new texttospeech(getactivity().getapplicationcontext(), new texttospeech.oninitlistener()     {         @override         public void oninit(int status)         {             if(status != texttospeech.error)             {                 t1.setlanguage(locale.uk);             }         }     });  }  @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {      view view = inflater.inflate(r.layout.fragment_home, container, false);       resulttext = (textview)view.findviewbyid(r.id.tvresult);     resulttext2 = (textview)view.findviewbyid(r.id.tvresult2);     button = (button)view.findviewbyid(r.id.imagebutton);      button.setonclicklistener(new view.onclicklistener()     {         @override         public void onclick(view v)         {             if(v.getid() == r.id.imagebutton)             {                  promptspeechinput();             }         }     });       return view;  }    public void promptspeechinput() {     intent = new intent(recognizerintent.action_recognize_speech);     i.putextra(recognizerintent.extra_language_model, recognizerintent.language_model_free_form);     i.putextra(recognizerintent.extra_language, locale.getdefault());     i.putextra(recognizerintent.extra_prompt, "say something!");      try     {         startactivityforresult(i, 100);         resulttext.settext("");         resulttext2.settext("");       }     catch(activitynotfoundexception a)     {         //toast.maketext.(mainactivity.this, "sorry device not support speech language! ", toast.length_long).show();     } }   static final string[] texts =         {                 "i fine","i okay","i good","well doing good"         }; static final string[] what1 =         {                 "yes? can with?",                 "what?",                 "yes?",                 "yes? how can you?"          };  public void readtext() {     random r = new random();     string wow = texts[r.nextint(4)];     string = what1[r.nextint(4)];       if(tospeak.equals("how you") || tospeak.equals("hi ashley how you")|| tospeak.equals("hey ashley how you"))     {          t1.speak(wow, texttospeech.queue_flush, null);           resulttext2.settext(wow);      }     else  if(tospeak.equals("hey ashley") || tospeak.equals("hey")|| tospeak.equals("hey")|| tospeak.equals("ashley"))     {          t1.speak(what, texttospeech.queue_flush, null);           resulttext2.settext(what);      } }    public void onactivityresult(int request_code, int result_code, intent i) {     super.onactivityresult(request_code, result_code, i);      switch (request_code)     {         case 100: if(result_code == result_ok && != null) // have error @ line @ "result_ok"         {             arraylist<string> result = i.getstringarraylistextra(recognizerintent.extra_results);             string r1 = result.get(0);              resulttext.settext(result.get(0));             readtext();         }             break;     } } 

}

result_ok constant of activity class, cannot direclty in fragment. use following :

if(result_code == activity.result_ok) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -