java - Unreachable Code error -


i making app called rome, city of rome. have activity called eten means food , want activity open pdf-file called etenlijst.pdf when openened.

i got following code:

package com.example.rome;  import android.os.bundle; import android.app.activity; import android.view.menu; import android.view.menuitem; import android.support.v4.app.navutils; import android.content.intent; import android.widget.button; import android.view.view; import android.widget.toast; import android.net.uri; import java.io.file; import android.content.activitynotfoundexception;    public class eten extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_eten);     // show button in action bar.     // getactionbar().setdisplayhomeasupenabled(true); }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.activity_eten, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     switch (item.getitemid()) {     case android.r.id.home:         // id represents home or button. in case of         // activity, button shown. use navutils allow users         // navigate 1 level in application structure.         // more details, see navigation pattern on android design:         //         // http://developer.android.com/design/patterns/navigation.html#up-vs-back         //         navutils.navigateupfromsametask(this);         return true;     }     return super.onoptionsitemselected(item);       button openpdf = (button) findviewbyid(r.id.openpdfbutton);     openpdf.setonclicklistener(new view.onclicklistener()     {          public void onclick(view v)          {             file pdffile = new file("/rome/etenlijst.pdf");              if(pdffile.exists())              {                 uri path = uri.fromfile(pdffile);                  intent pdfintent = new intent(intent.action_view);                 pdfintent.setdataandtype(path, "application/pdf");                 pdfintent.setflags(intent.flag_activity_clear_top);                  try                 {                     startactivity(pdfintent);                 }                 catch(activitynotfoundexception e)                 {                     toast.maketext(eten.this, "installeer een geschikte applicatie om pdf's mee te openen", toast.length_long).show();                  }             }          }     }); }    } 

but @ line containing: button openpdf = (button) findviewbyid(r.id.openpdfbutton); openpdf.setonclicklistener(new view.onclicklistener() {

eclipse gives me error: unreachable code have no idea how solve this, asking you. know how solve , why error comes up?

thanks in advance, ide

p.s. not native-english speaker please @ question , not @ grammar.

edit:

i got following helpful answers:

package com.example.rome;  import android.os.bundle; import android.app.activity; import android.view.menu; import android.view.menuitem; import android.support.v4.app.navutils; import android.content.intent; import android.widget.button; import android.view.view; import android.widget.toast; import android.net.uri; import java.io.file; import android.content.activitynotfoundexception;    public class eten extends activity {  @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_eten); // show button in action bar. // getactionbar().setdisplayhomeasupenabled(true);        /****  looks place   *****/     button openpdf = (button) findviewbyid(r.id.openpdfbutton);     openpdf.setonclicklistener(new view.onclicklistener()     {      public void onclick(view v)      {         file pdffile = new file("/rome/etenlijst.pdf");          if(pdffile.exists())          {             uri path = uri.fromfile(pdffile);              intent pdfintent = new intent(intent.action_view);             pdfintent.setdataandtype(path, "application/pdf");             pdfintent.setflags(intent.flag_activity_clear_top);              try             {                 startactivity(pdfintent);             }             catch(activitynotfoundexception e)             {                 toast.maketext(eten.this, "installeer een geschikte applicatie om pdf's mee te openen", toast.length_long).show();              }         }      } }); } } 

but whenever go activity in app or click button won't open file or give toast? why?

after line return super.onoptionsitemselected(item); before button openpdf = (button) findviewbyid(r.id.openpdfbutton);, function return , hence next line (and lines after that) not executed.

your logic should such return should last statement of block occurs in.


Comments

Popular posts from this blog

Eclipse formatter for java ending braces -

ruby - Nesting modules inside of a Rails eninge gem -

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -