Array Index Out of Bounds Exception - Android -
Array Index Out of Bounds Exception - Android -
i'm getting array out of bounds error. i'm setting array values in try/catch block i'm not sure why i'm getting array out of bounds error.
private static string profilename; private string identity = null; private string address = null; private boolean valid = false; private int profileid; public string fullname=""; private linkedhashmap<string, string> namevalues = new linkedhashmap<string, string>(0); public profile(){ seek { string[] subnames = fullname.split("@"); this.profilename = subnames[0]; this.identity = subnames[1]; this.address = subnames[2]; this.valid = true; } grab (exception ex) { log.w(log_tag, "invalid profile, " + ex); this.valid = false; } }
putting value code:
public string getattributevalue(string key){ homecoming namevalues.get(key); } public void addattribute(string key, string value){ namevalues.put(key, value); }
here stack trace i'm getting issue:
01-11 01:37:20.721: i/activitythread(1759): pub com.whooznear.android: com.whooznear.android.profileprovider 01-11 01:37:21.142: d/dalvikvm(1759): gc_for_alloc freed 42k, 4% free 6337k/6595k, paused 139ms 01-11 01:37:21.174: i/dalvikvm-heap(1759): grow heap (frag case) 6.805mb 588816-byte allocation 01-11 01:37:21.472: d/dalvikvm(1759): gc_concurrent freed 8k, 4% free 6903k/7175k, paused 20ms+14ms 01-11 01:37:24.974: d/dalvikvm(1759): gc_for_alloc freed 603k, 11% free 6666k/7431k, paused 81ms 01-11 01:37:25.142: d/dalvikvm(1759): gc_concurrent freed <1k, 4% free 7167k/7431k, paused 6ms+14ms 01-11 01:37:25.642: w/profile(1759): invalid profile, java.lang.arrayindexoutofboundsexception: index=1 length=1 01-11 01:46:21.692: w/iinputconnectionwrapper(1759): showstatusicon on inactive inputconnection 01-11 01:46:25.836: d/dalvikvm(1759): gc_explicit freed 384k, 6% free 7110k/7559k, paused 9ms+5ms
i/s sure profile
constructor , not sure how , when fullname
string assigned? must have check bounds/length of array before utilize it.
try,
string[] subnames = fullname.split("@"); if(subnames.length==3) { this.profilename = subnames[0]; this.identity = subnames[1]; this.address = subnames[2]; this.valid = true; }
android arrays
Comments
Post a Comment