我正在使用volley,php和mysql进行活动以更新android studio中的用户配置文件。但是每当我单击“保存”按钮以保存所有信息时,什么都没有发生
android活动
public class ProfileInfoSignup extends AppCompatActivity {
ImageView dp;
ProgressBar pb;
EditText save_name,save_bio;
Button b1;
RequestQueue requestQueue;
boolean IMAGE_STATUS = false;
Bitmap profilePicture;
String name,bio,profile;
String user_email;
private static String SIGNUP_URL = "http://10.0.2.2/app2/profile_ru.php?apicall=updateuser";
SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile_info_signup);
dp=findViewById(R.id.circleView);
save_name=findViewById(R.id.edit_name);
save_bio=findViewById(R.id.edit_bio);
b1=findViewById(R.id.btn_start);
pb=findViewById(R.id.progress_bar3);
sp=getApplicationContext().getSharedPreferences("myPref", Context.MODE_PRIVATE);
if(sp.contains("user_email")) {
user_email = sp.getString("user_email", "Data not found");
}else{
Toast.makeText(getApplicationContext(), "no email found", Toast.LENGTH_SHORT).show();
}
//creating request queue
requestQueue = Volley.newRequestQueue(this);
//Adding onClickListener to the ImageView to select the profile Picture
dp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 1000);
//result will be available in onActivityResult which is overridden
}
});
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
name = save_name.getText().toString();
bio = save_bio.getText().toString();
if ( //perform validation by calling all the validate functions inside the IF condition
validateName(name) &&
validateBio(bio)&&
validateProfile()
) {
//Validation Success
convertBitmapToString(profilePicture);
saveProfileInfo(SIGNUP_URL,name,bio,user_email);
}
}
});
}
private void saveProfileInfo(String signupUrl, final String getuserName, final String getuserBio, final String getuserEmail) {
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST, signupUrl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
Toast.makeText(getApplicationContext(), "making new json object and going to another activity", Toast.LENGTH_LONG).show();
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.getBoolean("success")) {
Toast.makeText(getApplicationContext(), "Connected to json", Toast.LENGTH_LONG).show();
Intent intent = new Intent(ProfileInfoSignup.this, Activity2.class);
startActivity(intent);
} else
Toast.makeText(getApplicationContext(), "Something went wrong", Toast.LENGTH_LONG).show();
}catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> param = new HashMap<String, String>();
param.put("name", getuserName);
param.put("bio", getuserBio);
param.put("email", getuserEmail);
return param;
}
};
int socketTimeout = 30000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
stringRequest.setRetryPolicy(policy);
requestQueue.add(stringRequest);
}
private void convertBitmapToString(Bitmap profilePicture) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
profilePicture.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] array = byteArrayOutputStream.toByteArray();
profile = Base64.encodeToString(array, Base64.DEFAULT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1000 && resultCode == Activity.RESULT_OK && data != null) {
//Image Successfully Selected
Toast.makeText(getApplicationContext(), "Image successfully selected", Toast.LENGTH_SHORT).show();
try {
//parsing the Intent data and displaying it in the imageview
Uri imageUri = data.getData();//Geting uri of the data
InputStream imageStream = getContentResolver().openInputStream(imageUri);//creating an imputstrea
profilePicture = BitmapFactory.decodeStream(imageStream);//decoding the input stream to bitmap
dp.setImageBitmap(profilePicture);
IMAGE_STATUS = true;//setting the flag
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
private boolean validateName(String string) {
if (string.equals("")) {
save_name.setError("Enter Your Name");
return false;
} else if (string.length() > 50) {
save_name.setError("Maximum 50 Characters");
return false;
}
return true;
}
private boolean validateBio(String string) {
if (string.equals("")) {
save_bio.setError("Enter Your Email Address");
return false;
} else if (string.length() > 300) {
save_name.setError("Maximum 300 Characters");
return false;
}
return true;
}
private boolean validateProfile() {
if (!IMAGE_STATUS)
Toast.makeText(this, "Select A Profile Picture", Toast.LENGTH_SHORT).show();
return IMAGE_STATUS;
}
}
每次我运行应用程序并单击“保存”按钮时,都会在日志中出现
08-04 15:05:23.058 4409-4431/com.example.user.myapplication D/EGL_emulation: eglMakeCurrent: 0xb2eb8860: ver 2 0 (tinfo 0xb2e8b280)
08-04 15:05:23.180 1384-4481/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 1865147 , only wrote 1864800
08-04 15:05:23.848 4409-4409/com.example.user.myapplication W/System.err: org.json.JSONException: Value Record of type java.lang.String cannot be converted to JSONObject
at org.json.JSON.typeMismatch(JSON.java:111)
at org.json.JSONObject.<init>(JSONObject.java:163)
at org.json.JSONObject.<init>(JSONObject.java:176)
08-04 15:05:23.849 4409-4409/com.example.user.myapplication W/System.err: at com.example.user.myapplication.Login.ProfileInfoSignup$3.onResponse(ProfileInfoSignup.java:114)
at com.example.user.myapplication.Login.ProfileInfoSignup$3.onResponse(ProfileInfoSignup.java:109)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:67)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
08-04 15:05:23.850 4409-4409/com.example.user.myapplication W/System.err: at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
08-04 15:05:23.851 4409-4409/com.example.user.myapplication W/System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
php
@$name= $_POST['name'];
@$bio=$_POST['bio'];
@$email=$_POST['email'];
@$id=$_POST['id'];
if(!empty($_POST['name']) && !empty($_POST['bio']) && !empty($_POST['email']) )
{
$result="SELECT id FROM accounts where email='$email'";
$row = mysqli_fetch_assoc(mysqli_query($con,$result));
$id=$row['id'];
$Sql_Query =mysqli_prepare($con,"UPDATE profile SET name= ?, bio = ? WHERE id = ?");
/* bind parameters for markers */
mysqli_stmt_bind_param($Sql_Query, "ssi", $name,$bio,$id);
/* execute query */
$sql= mysqli_stmt_execute($Sql_Query);
if($sql){
echo 'Record Updated Successfully';
}
else{
echo 'Something went wrong, whether id is not present or something else'.mysqli_error($con);
}
}else
{
echo 'missing parameters';
}
我不知道问题出在php还是android代码中。 任何帮助将不胜感激