camera - Android App only working One time, then crashes -


okay having problem getting app work. have game needs few pictures , strings user. have opening screen (openingscreen) acts splash screen opens menu (menuscreen). there user can pick go game or go activity shows current pictures (pickscreen). user can go activity , there open activity gives larger version of picture have picked or default picture (picone). here user has option take new picture , change current strings. part of works great. problem occurs when:

after user picks picture , backs out of app. next time open it, force close either when go pickscreen or after press done after taking new picture , when go picone activity. not same thing everytime, crashes @ 1 of points.

the other issue happens when change 3 string names. after pressing save , going pickscreen, app crashes when going picone or if out of app crashes when going menuscreen pickscreen.

i know lot of code at, have spent lot of time looking around , getting code different places app , @ point cannot figure out. figure there many people more knowledge me out there, asking help. know cannot ask question without showing have been doing work, here is.

why may app work once , crash in various spots second time in? way work fine after force close, again once. , why force close when change strings?

thanks everyone!!

the picone class

public class picone extends activity implements onclicklistener { imageview iv; edittext c1, c2, c3; button cam, save; bitmap bit, bmp,other; intent i; uri urisavedimage; string imagefilepath10 = "", name1="", name2="", name3=""; final static int cameradata = 0;  boolean camera; int camorgal10 = 0; sharedpreferences gamedata;      @override     protected void oncreate(bundle savedinstancestate)  {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.picone);         camera = false;         iv = (imageview)findviewbyid(r.id.piciv);         cam = (button)findviewbyid(r.id.cambutton);         save = (button)findviewbyid(r.id.savebut);         e1 = (edittext)findviewbyid(r.id.enter1);         e2 = (edittext)findviewbyid(r.id.enter2);         e3 = (edittext)findviewbyid(r.id.enter3);          cam.setonclicklistener(this);         save.setonclicklistener(this); }     public void onclick(view v) {         // todo auto-generated method stub         switch(v.getid())         {         //camera         case r.id.cambutton:             camorgal10 = 1;             = new intent(android.provider.mediastore.action_image_capture);                            file imagesfolder = new file(environment.getexternalstoragedirectory(), "myspot");              imagesfolder.mkdirs(); // <----              string filename = "image_1.png";              file output = new file(imagesfolder, filename);                          urisavedimage = uri.fromfile(output);                      i.putextra(mediastore.extra_output, urisavedimage);             i.setflags(intent.flag_activity_clear_top);             startactivityforresult(i, cameradata);             break;          case r.id.savebut:             camera = true;             name1 = e1.gettext().tostring();             name2 = e2.gettext().tostring();             name3 = e3.gettext().tostring();             sharedpreferences.editor editor = gamedata.edit();             editor.putint("num10camgal", camorgal10);             editor.putstring("num10name1", name1);             editor.putstring("num10name2", name2);             editor.putstring("num10name3", name3);             editor.commit();             intent gopt = new intent(this, pickscreen.class);             gopt.setflags(intent.flag_activity_clear_top);             gopt.setflags(intent.flag_activity_single_top);             finish();             startactivity(gopt);                             break;          }     }      public boolean onkeydown(int keycode, keyevent event)     {         if(keycode == keyevent.keycode_back)         {             camera = true;             name1 = e1.gettext().tostring();             name2 = e2.gettext().tostring();             name3 = e3.gettext().tostring();             sharedpreferences.editor editor = gamedata.edit();             editor.putint("num10camgal", camorgal10);             editor.putstring("num10name1", name1);             editor.putstring("num10name2", name2);             editor.putstring("num10name3", name3);             editor.commit();             intent gopt = new intent(this, pickscreen.class);             gopt.setflags(intent.flag_activity_clear_top);             gopt.setflags(intent.flag_activity_single_top);             finish();             startactivity(gopt);              return true;         }         return super.onkeydown(keycode, event);     }         @override     protected void onactivityresult(int requestcode, int resultcode,             intent data) {         // todo auto-generated method stub         super.onactivityresult(requestcode, resultcode, data);         if(requestcode == cameradata)              {                      if(resultcode == result_ok && data.hasextra("data"))                      {                                  bmp = (bitmap) data.getextras().get("data");                     iv.setimagebitmap(bmp);                 }                      else if (resultcode == result_canceled)                     {                             toast.maketext(getapplicationcontext(), "cancelled",toast.length_short).show();                 }               }         }        @override     protected void onpause() {         // todo auto-generated method stub          super.onpause();      }      @override     protected void onresume() {         // todo auto-generated method stub           if(openingscreen.isexit)         {             finish();         }         gamedata = getsharedpreferences(menuscreen.myfolder, 0);         name1 = slotdata.getstring("num10name1", "one");         name2 = slotdata.getstring("num10name2", "two");         name3 = slotdata.getstring("num10name3", "three");         e1.settext(name1);         e2.settext(name2);         e3.settext(name3);         camorgal10 = gamedata.getint("num10camgal", 0);         if(camorgal10 == 0)         {             bit = bitmapfactory.decoderesource(getresources(), r.drawable.red);         }         else if(camorgal10 == 1)         {             file imgfile = new file(environment.getexternalstoragedirectory() + "/myspot/image_1.png");             if(imgfile.exists())             {                bit = bitmapfactory.decodefile(imgfile.getabsolutepath());                }             else             {                 bit = bitmapfactory.decoderesource(getresources(), r.drawable.red);             }         }          else         {             bit = bitmapfactory.decoderesource(getresources(), r.drawable.red);         }                    iv.setimagebitmap(bit);         super.onresume();     } } 

openingscreen

public class openingscreen extends activity { /** called when activity first created. */  public static boolean isexit = false;  @override    public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);     isexit = false;     thread timer = new thread(){         public void run(){             try{                 sleep(2500);             } catch(interruptedexception e){              } finally{                 intent tomenu = new intent(getapplicationcontext(), menuscreen.class);                 tomenu.setflags(intent.flag_activity_clear_top);                 //tomenu.setflags(intent.flag_activity_no_history);                 finish();                 startactivity(tomenu);                               }                        }     };     timer.start(); }  @override protected void onpause() {     // todo auto-generated method stub     finish();     super.onpause();         }  @override protected void onresume() {     // todo auto-generated method stub     if(isexit)     {         finish();     }      super.onresume(); }     } 

menuscreen

public class menuscreen extends activity implements onclicklistener { float x,y; int camorgal = 0; imagebutton play, edit, more; intent i; public static string myfolder = "gamedata"; @override protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     setcontentview(r.layout.menu);     play = (imagebutton)findviewbyid(r.id.ibplay);     edit = (imagebutton)findviewbyid(r.id.ibedit);     more = (imagebutton)findviewbyid(r.id.ibmore);     play.setonclicklistener(this);     edit.setonclicklistener(this);     more.setonclicklistener(this); }  public boolean onkeydown(int keycode, keyevent event) {     if(keycode == keyevent.keycode_back)     {         openingscreen.isexit = true;         finish();         return true;     }     return super.onkeydown(keycode, event); }  public void onclick(view v) {     // todo auto-generated method stub     switch(v.getid())     {     case r.id.ibplay:         = new intent(getapplicationcontext(), thegame.class);         i.setflags(intent.flag_activity_clear_top);         finish();         startactivity(i);                    break;     case r.id.ibedit:         = new intent(this, pickscreen.class);         i.setflags(intent.flag_activity_clear_top);         finish();         startactivity(i);                    break;     case r.id.ibmore:          break;     } }  } 

pickscreen

public class pickscreen extends activity implements onclicklistener { button bpic1, bpic2, bpic3; imageview ivpic3,ivpic2, ivpic1; textview tvpic3a, tvpic3b, tvpic3c, tvpic2a, tvpic2b, tvpic2c, tvpic1a, tvpic1b, tvpic1c; intent pagemove; sharedpreferences gamedata; int camorgal10 = 0; string threenamea = "", threenameb = "", threenamec = "", twonamea = "", twonameb = "", twonamec = "", onenamea = "", onenameb = "", onenamec = "";  bitmap bmp1, bmp2,bmp3; @override protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     setcontentview(r.layout.paytable);                 intitializethings();         }   public void intitializethings() {     bpic1 = (button)findviewbyid(r.id.pic1but);     bpic2 = (button)findviewbyid(r.id.pic2but);     bpic3 = (button)findviewbyid(r.id.pic3but);     ivpic3 = (imageview)findviewbyid(r.id.ivpic3a);     ivpic2 = (imageview)findviewbyid(r.id.ivpic2a);     ivpic1 = (imageview)findviewbyid(r.id.ivpic1a);     tvpic3a = (textview)findviewbyid(r.id.pic3tva);     tvpic3b = (textview)findviewbyid(r.id.pic3tvb);     tvpic3c = (textview)findviewbyid(r.id.pic3tvc);     tvpic2a = (textview)findviewbyid(r.id.pic2tva);     tvpic2b = (textview)findviewbyid(r.id.pic2tvb);     tvpic2c = (textview)findviewbyid(r.id.pic2tvc);     tvpic1a = (textview)findviewbyid(r.id.pic1tva);     tvpic1b = (textview)findviewbyid(r.id.pic1tvb);     tvpic1c = (textview)findviewbyid(r.id.pic1tvc);       bpic1.setonclicklistener(this);     bpic2.setonclicklistener(this);     bpic3.setonclicklistener(this); }  public void onclick(view v) {     // todo auto-generated method stub     switch(v.getid())     {     case r.id.pic1but:         pagemove = new intent(getapplicationcontext(), picone.class);         pagemove.setflags(intent.flag_activity_clear_top);         pagemove.setflags(intent.flag_activity_single_top);         //pagemove.setflags(intent.flag_activity_no_history);         finish();         startactivity(pagemove);          break;     case r.id.pic2but:         pagemove = new intent(getapplicationcontext(), pictwo.class);         pagemove.setflags(intent.flag_activity_clear_top);         //pagemove.setflags(intent.flag_activity_no_history);         startactivity(pagemove);         finish();                           break;     case r.id.pic3but:         pagemove = new intent(getapplicationcontext(), picthree.class);         pagemove.setflags(intent.flag_activity_clear_top);         //pagemove.setflags(intent.flag_activity_no_history);         startactivity(pagemove);         finish();                              break;                 } }  public boolean onkeydown(int keycode, keyevent event) {     if(keycode == keyevent.keycode_back)     {         intent goop = new intent(this, menuscreen.class);         goop.setflags(intent.flag_activity_clear_top);         goop.setflags(intent.flag_activity_single_top);         finish();         startactivity(goop);          return true;     }     return super.onkeydown(keycode, event); }   @override protected void onpause() {     // todo auto-generated method stub     super.onpause();  }  @override protected void onresume() {     // todo auto-generated method stub     super.onresume();              gamedata = getsharedpreferences(menuscreen.myfolder, 0);         onenamea = gamedata.getstring("num10name1", "one");         onenameb = gamedata.getstring("num10name2", "two");         onenamec = gamedata.getstring("num10name3", "three");         camorgal10 = gamedata.getint("num10camgal", 0);           if(camorgal10 == 1)         {             file pic1 = new file(environment.getexternalstoragedirectory() + "/myspot/image_1.png");             if(pic1.exists())             {                 bmp1 = bitmapfactory.decodefile(pic1.getabsolutepath());             }             else             {                 bmp1 = bitmapfactory.decoderesource(getresources(), r.drawable.red);             }         }          else if(camorgal10 == 0)         {             bmp1 = bitmapfactory.decoderesource(getresources(), r.drawable.red);         }         else         {             bmp1 = bitmapfactory.decoderesource(getresources(), r.drawable.red);         }           file pic2 = new file(environment.getexternalstoragedirectory() + "/myspot/image_2.png");         file pic3 = new file(environment.getexternalstoragedirectory() + "/myspot/image_3.png");           if(pic2.exists())         {             bmp2 = bitmapfactory.decodefile(pic2.getabsolutepath());         }         else         {             bmp2 = bitmapfactory.decoderesource(getresources(), r.drawable.purple);         }         if(pic3.exists())         {             bmp3 = bitmapfactory.decodefile(pic3.getabsolutepath());         }         else         {             bmp3 = bitmapfactory.decoderesource(getresources(), r.drawable.green);         }           ivpic3.setimagebitmap(bmp3);          ivpic2.setimagebitmap(bmp2);          ivpic1.setimagebitmap(bmp1);          tvpic1a.settext(onenamea);         tvpic1b.settext(onenameb);         tvpic1c.settext(onenamec);  }   }  

logcat give stack trace, , use debug pinpoint place it's crashing. debugging modern application reading through code, oop code, impossible.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -