Android App exits after choosing image from gallery -


here's code:

package com.survey.sop;   import android.net.uri; import android.os.bundle; import android.provider.mediastore; import android.app.activity; import android.content.contenturis; import android.content.intent; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.util.log; import android.view.view; import android.widget.button; import android.widget.imageview; import android.widget.textview; import android.widget.toast; import android.view.view.onclicklistener;  public class signup extends activity  {      private static int result_load_image = 1;    sqlitedatabase mydb = null;    textview name ;    textview address;    textview birthdate;    textview email;    textview username;    textview password;    button signup;    imageview imgavatar;    int id_to_update = 0;       @override    protected void oncreate(bundle savedinstancestate)     {       super.oncreate(savedinstancestate);       setcontentview(r.layout.signup);        name = (textview) findviewbyid(r.id.txtname);       address = (textview) findviewbyid(r.id.txtaddress);       birthdate = (textview) findviewbyid(r.id.txtbdate);       email = (textview) findviewbyid(r.id.txtemail);       username = (textview) findviewbyid(r.id.txtuser);       password = (textview) findviewbyid(r.id.txtpwd);       signup = (button) findviewbyid(r.id.btnregister);       imgavatar = (imageview) findviewbyid(r.id.imgavatar);         mydb = this.openorcreatedatabase("surveydb", mode_private,  null);        /////////////////////////////////////////////////////////////////////////       imgavatar.setonclicklistener(new view.onclicklistener()          {          @override         public void onclick(view v) {             // todo auto-generated method stub             intent = new intent(intent.action_pick, android.provider.mediastore.images.media.external_content_uri);             startactivityforresult(i, result_load_image);         }          }); ///////////////////////////////////////////////////////////////////////////        signup.setonclicklistener(new onclicklistener()     {         public void onclick(view v)        {                       try                      {                       string usernamestr = username.gettext().tostring();                       string passwordstr = password.gettext().tostring();                       string namestr = name.gettext().tostring();                       string addressstr = address.gettext().tostring();                       string birthdatestr = birthdate.gettext().tostring();                         if (usernamestr.equals("") || passwordstr.equals("") || namestr.equals("") || address.equals("") || birthdate.equals(""))                        {                           toast.maketext(getbasecontext(), "please fill required fields.", 2).show();                       }                        else                        {                            mydb.execsql("insert users " + "(username, userpwd, name, address, birthdate, level)"                           + " values ('" + usernamestr + "', '" + passwordstr + "','"                           + namestr + "', '" + addressstr + "','"                           + birthdatestr + "', 'user');");                            toast.maketext(getbasecontext(), "successfully registered!", 2).show();                              username.settext("");                             password.settext("");                             name.settext("");                             address.settext("");                             birthdate.settext("");                       }                     }                     catch (exception e)                     {                         log.e("error", "error", e);                          toast.maketext(getbasecontext(), "error signing up.", toast.length_long).show();                     }         }     });      }     @override    public void onactivityresult(int requestcode, int resultcode, intent data)    {        super.onactivityresult(requestcode, resultcode, data);         if (resultcode == result_ok)            {            uri selectedimageuri = data.getdata();            string s = getrealpathfromuri(selectedimageuri);     //testing            toast.maketext(getbasecontext(), s, 4).show();            }    }      private string getrealpathfromuri(uri uri)     {     // todo auto-generated method stub     string[] projection = { mediastore.images.media.data };     @suppresswarnings("deprecation")     cursor cursor = managedquery(uri, projection, null, null, null);     int column_index = cursor.getcolumnindexorthrow(mediastore.images.media.data);     cursor.movetofirst();     return cursor.getstring(column_index);     }   @override    protected void onpause() {     // todo auto-generated method stub     super.onpause();     finish();    }  } 

what happens when click image, opens gallery can choose pictures.

i want test if codes can string of selected image's directory can store it/call it

from database — unfortunately, after choose image, app closes.

i don't know android programming, still new one.

thanks in advance.

here's logcat :

06-26 15:18:56.218: v/phonewindow(26324): decorview setvisiblity: visibility = 4 06-26 15:18:56.227: v/phonewindow(26324): decorview setvisiblity: visibility = 0 06-26 15:18:56.256: v/inputmethodmanager(26324): onwindowfocus: null softinputmode=288 first=true flags=#8010500 06-26 15:18:56.256: v/inputmethodmanager(26324): start input: com.android.internal.policy.impl.phonewindow$decorview{42729b50 v.e..... r.....id 0,0-480,800} ic=null tba=android.view.inputmethod.editorinfo@4272e388 controlflags=#104 06-26 15:18:56.259: v/inputmethodmanager(26324): starting input: bind result=inputbindresult{com.android.internal.view.iinputmethodsession$stub$proxy@4272ec18 com.android.inputmethod.latin/.latinime #1252} 06-26 15:18:56.295: i/inputmethodmanager(26324): handlemessage: msg_set_active true, false 06-26 15:18:59.298: v/phonewindow(26324): decorview setvisiblity: visibility = 4 06-26 15:18:59.301: v/phonewindow(26324): decorview setvisiblity: visibility = 0 06-26 15:18:59.307: v/inputmethodmanager(26324): not ime target window, ignoring 06-26 15:18:59.327: v/inputmethodmanager(26324): onwindowfocus: android.widget.edittext{42736968 vfed..cl .f....id 24,368-456,440 #7f080007 app:id/txtlusername} softinputmode=288 first=true flags=#8010500 06-26 15:18:59.328: v/inputmethodmanager(26324): start input: android.widget.edittext{42736968 vfed..cl .f....id 24,368-456,440 #7f080007 app:id/txtlusername} ic=com.android.internal.widget.editableinputconnection@4273ed18 tba=android.view.inputmethod.editorinfo@4273ec08 controlflags=#107 06-26 15:18:59.331: v/inputmethodmanager(26324): starting input: bind result=inputbindresult{com.android.internal.view.iinputmethodsession$stub$proxy@4273f8f8 com.android.inputmethod.latin/.latinime #1253} 06-26 15:19:00.847: i/surfacetextureclient(26324): [stc::queuebuffer] (this:0x522866f0) fps:2.02, dur:1488.66, max:512.32, min:483.63 06-26 15:19:01.653: v/provider/settings(26324):  settings cache , name = sound_effects_enabled , value = 0 06-26 15:19:01.654: v/inputmethodmanager(26324): not ime target window, ignoring 06-26 15:19:01.673: v/inputmethodmanager(26324): not ime target window, ignoring 06-26 15:19:01.704: v/inputmethodmanager(26324): focusout: android.widget.edittext{42736968 vfed..cl .f....i. 24,368-456,440 #7f080007 app:id/txtlusername} mservedview=android.widget.edittext{42736968 vfed..cl .f....i. 24,368-456,440 #7f080007 app:id/txtlusername} winfocus=false 06-26 15:19:02.352: i/surfacetextureclient(26324): [stc::queuebuffer] (this:0x522866f0) fps:1.99, dur:1505.53, max:617.73, min:387.83 06-26 15:19:02.357: v/inputmethodmanager(26324): onwindowfocus: android.widget.edittext{42736968 vfed..cl .f....id 24,368-456,440 #7f080007 app:id/txtlusername} softinputmode=32 first=false flags=#8010500 06-26 15:19:02.360: v/inputmethodmanager(26324): focusout: android.widget.edittext{42736968 vfed..cl .f....id 24,368-456,440 #7f080007 app:id/txtlusername} mservedview=android.widget.edittext{42736968 vfed..cl .f....id 24,368-456,440 #7f080007 app:id/txtlusername} winfocus=false 06-26 15:19:02.391: v/phonewindow(26324): decorview setvisiblity: visibility = 4 06-26 15:19:02.395: v/phonewindow(26324): decorview setvisiblity: visibility = 0 06-26 15:19:02.448: v/inputmethodmanager(26324): onwindowfocus: android.widget.edittext{42750b90 vfed..cl .f....id 0,203-480,275 #7f08000a app:id/txtname} softinputmode=288 first=true flags=#8010500 06-26 15:19:02.449: d/inputmethodmanager(26324): deactivate inputconnection in controlledinputconnectionwrapper. 06-26 15:19:02.450: v/inputmethodmanager(26324): start input: android.widget.edittext{42750b90 vfed..cl .f....id 0,203-480,275 #7f08000a app:id/txtname} ic=com.android.internal.widget.editableinputconnection@42762a48 tba=android.view.inputmethod.editorinfo@42762938 controlflags=#107 06-26 15:19:02.452: v/inputmethodmanager(26324): starting input: bind result=inputbindresult{com.android.internal.view.iinputmethodsession$stub$proxy@427635f0 com.android.inputmethod.latin/.latinime #1254} 06-26 15:19:03.417: v/provider/settings(26324):  settings cache , name = sound_effects_enabled , value = 0 06-26 15:19:03.493: v/inputmethodmanager(26324): focusout: android.widget.edittext{42750b90 vfed..cl .f....i. 0,203-480,275 #7f08000a app:id/txtname} mservedview=android.widget.edittext{42750b90 vfed..cl .f....i. 0,203-480,275 #7f08000a app:id/txtname} winfocus=false 06-26 15:19:03.518: i/surfacetextureclient(26324): [stc::queuebuffer] (this:0x52524000) fps:2.92, dur:1025.88, max:529.50, min:25.97 06-26 15:19:03.701: i/inputmethodmanager(26324): handlemessage: msg_set_active false, true 06-26 15:19:03.702: i/inputmethodmanager(26324): handlemessage: msg_unbind 1254 06-26 15:19:03.703: d/inputmethodmanager(26324): deactivate inputconnection in controlledinputconnectionwrapper. 06-26 15:19:03.703: w/iinputconnectionwrapper(26324): showstatusicon on inactive inputconnection 

  1. if onactivityresult() called, check requestcode valid.

    @override public void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);      if (resultcode == result_ok && requestcode == result_load_image)     {         uri selectedimageuri = data.getdata();         string s = getrealpathfromuri(selectedimageuri);         //testing        toast.maketext(getbasecontext(), s, 4).show();     } } 
  2. if device memory isn't sufficient, have save member variables used before calling startactivityforresult

    @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     if (savedinstancestate == null) {     }     else {         // sample member variables         moutputfileuri = uri.parse(savedinstancestate.getstring("moutputfileuri", ""));         mstep = savedinstancestate.getint("mstep");         mcropsizex = savedinstancestate.getint("mcropsizex");         mcropsizey = savedinstancestate.getint("mcropsizey");     } }  @override protected void onsaveinstancestate(bundle outstate) {     super.onsaveinstancestate(outstate);     outstate.putstring("moutputfileuri", (moutputfileuri != null)? moutputfileuri.tostring(): "");     outstate.putint("mstep", mstep);     outstate.putint("mcropsizex", mcropsizex);     outstate.putint("mcropsizey", mcropsizey); 

    }


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -