java - Can't open an activity in android -


i have problems android programming. trying open activity on phone, fails. says unfortunately program has stopped. not know how solve this, try connect method below. appreciated. please ask if did not specify enough.

    public void addglossary(view v){     intent intent = new intent (this, addglossary.class);     button buttonzero = (button) findviewbyid(r.id.buttonzero);     startactivity(intent);  } 

here code activity:

public abstract class addglossary extends activity implements onclicklistener, oninitlistener {       private int my_data_check_code = 0;      private texttospeech mytts;   private mediaplayer mmediaplayer;       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_add_glossary);           button speakbutton = (button)findviewbyid(r.id.speak);         speakbutton.setonclicklistener(this);           intent checkttsintent = new intent();         checkttsintent.setaction(texttospeech.engine.action_check_tts_data);         startactivityforresult(checkttsintent, my_data_check_code);         mmediaplayer = new mediaplayer();         mmediaplayer = mediaplayer.create(this, r.raw.button);         mmediaplayer.setaudiostreamtype(audiomanager.stream_music);         mmediaplayer.start();         mmediaplayer.setoncompletionlistener(new oncompletionlistener() {             @override             public void oncompletion(mediaplayer mp) {                 mmediaplayer.stop();             }         });       }      public void buttonreturn(view v){         intent intent = new intent (this, mainactivity.class);         button buttonreturn = (button) findviewbyid(r.id.buttonreturn);         startactivity(intent);      }       public void startgame(view v){         intent intent = new intent (this, firstlevel.class);         button buttonstart = (button) findviewbyid(r.id.buttonstart);         startactivity(intent);        }         public void oninit(int initstatus) {         if(mytts.islanguageavailable(locale.us)==texttospeech.lang_available) {             mytts.setlanguage(locale.us);         }          else if (initstatus == texttospeech.error) {             toast.maketext(this, "sorry! text speech failed...", toast.length_long).show();         }      }       private void speakwords(string speech){         mytts.speak(speech, texttospeech.queue_flush, null);            }      public void buttonadd(){         //lagrar texten från textfältet man knappade in till string         edittext enteredtext = (edittext)findviewbyid(r.id.enter);         string words = enteredtext.gettext().tostring();         speakwords(words);      }        protected void onactivityresult(int requestcode, int resultcode, intent data) {         if (requestcode == my_data_check_code) {             if (resultcode == texttospeech.engine.check_voice_data_pass) {                 mytts = new texttospeech(this, this);             }             else {                 intent installttsintent = new intent();                 installttsintent.setaction(texttospeech.engine.action_install_tts_data);                 startactivity(installttsintent);             }         }     }       @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_add_glossary, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     } } 

your adglossary class abstract class. android needs see concrete activity implementation start one.

remove abstract keyword , assuming have activity in manifest, should start.

**edit:**as chris stratton noted in comments, reason abstract placed go around implementing onclicklistener , oninitlistener. while code may have compiled, solution still unworkable.

so apart removing abstract qualifier, have implement interfaces.

solution: remove abstract modifier. compiler should detect unimplemented methods , should ask option add unimplemented methods or mark class abstract (the red squiggly lines show , should these options when move mouse on it). ask compiler add unimplemented methods. should have:

@override public void onclick(view view) {     // when clicked     // implement logic here }  @override public void oninit(int status) {     // implement logic here }  // done , should work 

just implement logic within above methods , should it.


Popular posts from this blog