Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
java.lang.StringIndexOutOfBoundsException solutions
how can i solve this error
Posted
Comments
[no name] 8-May-15 6:05am    
If I am not wrong then the index that is coming is not listed there in your scope. So put a check condition there to check the rance of your scope and make your requirement more robust.
seyed mahmud shahrokni 8-May-15 6:29am    
its better to share your code with us . thank you
Member 11420908 8-May-15 6:55am    
This is my code

public class MainActivity extends ActionBarActivity {

String seedValue = "MAKV2SPBNI99212";
String device,json;
String DeviceID = "490154203237518";
String ControllerDeviceID = "Null";
String PartnerMode = "None";
String PhoneModel="Samsung";
String PhoneNumber = "8056792232";
String PhoneOS = "Lollypop";
String CreatedOn = "15.02.1201";
String Status = "Active";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//// String seedValue = "MAKV2SPBNI99212";
// String normalText = "VIJAY";
// String normalTextEnc;
//// String Json="";
JSONObject jsonObject = new JSONObject();
try {
JSONObject jsonObject1=new JSONObject();
jsonObject1.accumulate("DeviceId",DeviceID);
jsonObject1.accumulate("ControllerDeviceID",ControllerDeviceID);
jsonObject1.accumulate("PartnerMode",PartnerMode);
jsonObject1.accumulate("PhoneModel",PhoneModel);
jsonObject1.accumulate("PhoneNumber",PhoneNumber);
jsonObject1.accumulate("PhoneOS",PhoneOS);
jsonObject1.accumulate("CreatedOn",CreatedOn);
jsonObject1.accumulate("Status",Status);
json=jsonObject1.toString();

} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
try {
device = AESHelper.encrypt(seedValue,json);
String normalTextDec = AESHelper.decrypt(seedValue,device);
TextView txe=(TextView)findViewById(R.id.textView);
txe.setTextSize(14);
txe.setText("Normal Text ::"+json +" \n Encrypted Value :: "+device +" \n Decrypted value :: "+normalTextDec);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Encryption ex=new Encryption();
ex.execute();
}
class Encryption extends AsyncTask
{
@Override
protected Object doInBackground(Object[] params) {
Httpt();
return null;
}
public void Httpt()
{
HttpPost httpPost1=new HttpPost("http://kredo.no-ip.org/SSMA/api/DevicesAPI/RegisterDevice?device="+device);
try {

HttpClient httpClient=new DefaultHttpClient();
HttpResponse response=httpClient.execute(httpPost1);
HttpEntity entity = response.getEntity();
String responseBody = EntityUtils.toString(entity); //To receive response from server
Log.v("response", responseBody.toString());

} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}
}
}
ZurdoDev 8-May-15 9:04am    
1. Don't put code like this in the comments. It's very hard to read. Click improve question and put it as part of your question.
2. IndexOutOfBounds means you're trying to access an index that does not exist.
3. Do not post all this code. Just the line that gives the error and any relevant code.
4. Show us which line caused the error.
5. Don't expect people to guess what the problem. Give us good info and you'll have an answer quickly.
AmanArora1987 9-May-15 2:55am    
Comment this line and try
// txe.setTextSize(14);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900