i trying using java , eclipse make applications (currently using b4a, want expand available resources, , ability make libraries)
when trying implement dialog using fragments, have followed example here.
i keep getting
05-06 13:40:21.060: e/sensormanager(18538): thread start 05-06 13:40:21.105: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0
i have tried debugging, debugger never stops on error (and new debugger, not sure how figure 1 out).
does see exception being caused? (just make sure wasn't fat finger anywhere, downloaded via git, , tried out, , received exact same errors in logcat)
here mainactivity.java:
package com.example.fragmenttest; import com.example.fragmenttest.editnamedialog.editnamedialoglistener; import android.os.bundle; import android.app.activity; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmentmanager; import android.view.menu; import android.widget.toast; public class mainactivity extends fragmentactivity implements editnamedialoglistener { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.fragment_edit_name); showeditdialog(); } private void showeditdialog() { fragmentmanager fm = getsupportfragmentmanager(); editnamedialog editnamedialog = new editnamedialog(); editnamedialog.show(fm, "fragment_edit_name"); } @override public void onfinisheditdialog(string inputtext) { toast.maketext(this, "hi, " + inputtext, toast.length_short).show(); } }
and here editnamedialog.java:
package com.example.fragmenttest; import android.support.v4.app.dialogfragment; import android.os.bundle; import android.view.keyevent; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.view.windowmanager.layoutparams; import android.view.inputmethod.editorinfo; import android.widget.edittext; import android.widget.textview; import android.widget.textview.oneditoractionlistener; public class editnamedialog extends dialogfragment implements oneditoractionlistener { public interface editnamedialoglistener { void onfinisheditdialog(string inputtext); } private edittext medittext; public editnamedialog() { // empty constructor required dialogfragment } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_edit_name, container); medittext = (edittext) view.findviewbyid(r.id.txt_your_name); getdialog().settitle("hello"); // show soft keyboard automatically medittext.requestfocus(); getdialog().getwindow().setsoftinputmode( layoutparams.soft_input_state_visible); medittext.setoneditoractionlistener(this); return view; } @override public boolean oneditoraction(textview v, int actionid, keyevent event) { if (editorinfo.ime_action_done == actionid) { // return input text activity editnamedialoglistener activity = (editnamedialoglistener) getactivity(); activity.onfinisheditdialog(medittext.gettext().tostring()); this.dismiss(); return true; } return false; } }
and string resource file:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">fragmenttest</string> <string name="hint_value">hint</string> <string name="your_name">your name</string> </resources>
complete stacktrace logcat: (no different @ top)
05-06 13:40:21.060: e/sensormanager(18538): thread start 05-06 13:40:21.105: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.105: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.110: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.200: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.205: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.205: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.210: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.215: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.275: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.275: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.300: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.300: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.300: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.470: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.470: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.725: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0 05-06 13:40:21.725: e/dynamiclayout(18538): java.lang.indexoutofboundsexception: charat: 0 >= length 0
edit : running on galaxy s3 running 4.1.2. when tried out on galaxy sl running 2.3.4, absolutely no logcat issues. tells me platform related, in searches, did not see related android version. follow question, know of issue jb (or else i've mentioned) might account error?
probably, exception thrown android.text.spannablestringbuilder#charat(int).
/** * return char @ specified offset within buffer. */ public char charat(int where) { int len = length(); if (where < 0) { throw new indexoutofboundsexception("charat: " + + " < 0"); } else if (where >= len) { throw new indexoutofboundsexception("charat: " + + " >= length " + len); } if (where >= mgapstart) return mtext[where + mgaplength]; else return mtext[where]; }
i guess kind of thread-unsafe operation performed in code.
for example, may worth trying move showeditdialog() oncreate(bundle) onresume(). if not solve issue, editnamedialog#oncreateview next check.
android api has many oncreatexxx methods, , there documented , undocumented things should avoid doing within methods.
Java - Indexoutofboundsexception: Charat: 0 = Length 0 On Some
ReplyDeleteVersions Of Android - >>>>> Download Now
>>>>> Download Full
Java - Indexoutofboundsexception: Charat: 0 = Length 0 On Some
Versions Of Android - >>>>> Download LINK
>>>>> Download Now
Java - Indexoutofboundsexception: Charat: 0 = Length 0 On Some
Versions Of Android - >>>>> Download Full
>>>>> Download LINK 8l