Ich erhalte dies in meiner Json-Methode. Ich versuche, Informationen aus meinem Server und MySQL-Datenbank zu erhalten und dann in meinem Benutzernamen Textansicht anzuzeigen. Das ist meine Json-Methode. Es wirft den Index außerhalb des Bereichsfehlers.Index 0 außerhalb des Bereichs [0 ... 0]
private void showJSON(String response) {
String username = "";
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray(Constantss.JSON_ARRAY);
JSONObject profileData = result.getJSONObject(0);
username = profileData.getString(Constantss.USERNAME);
System.out.println("first" + username);
} catch (JSONException e) {
e.printStackTrace();
}
usernameView.setText(username);
System.out.println("second" + username);
}
Wahrscheinlich nicht benötigt, aber das ist, wie ich meine Daten immer bin, Es funktioniert gut, ich bin in der Lage, die Id abrufen und auch die PHP-Code ausführen mir den Benutzernamen zu geben.
private void getData() {
class lata extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(), //Context
"us-east--------------", //Identity Pool ID
Regions.US_EAST_1 // Region
//Now we retrieve
);
// return null;
String identityID = credentialsProvider.getIdentityId();
Log.d("LogTag", "my ID is" + identityID);
String id = identityID;
String userid = identityID;
System.out.println("Id is" + identityID);
System.out.println("Id tis" + id);
String url = Constantss.PROFILE_URL + identityID;
StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Profile.this, error.getMessage().toString(), Toast.LENGTH_SHORT).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(Profile.this);
requestQueue.add(stringRequest);
return identityID;
}
}
lata pasta = new lata();
pasta.execute();
}
Das ist alles Java-Code. Wo kommt Mysqli ins Spiel? – tadman
Ich benutze PHP zu und Mysqli, um die Informationen abzurufen. –