我正在开发一个应用程序,它要求用户上传个人资料图片,当用户点击提交按钮时,个人资料图片将存储在数据库中。但是当用户尝试上传他们的个人资料照片时,它会给出错误。
这是我的android代码:
class ContentDATA extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Upload.this);
pDialog.setMessage("Registering...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting song json and parsing
*/
protected String doInBackground(String... args) {
// Building Parameters
java.util.List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("p_category", type[ch2]));
params.add(new BasicNameValuePair("p_name",p_name));
params.add(new BasicNameValuePair("p_content", p_content));
params.add(new BasicNameValuePair("p_price",price));
params.add(new BasicNameValuePair("prd_pic",profice_pic));
// getting JSON string from URL
String json = jsonParser.makeHttpRequest(DATA_URL, "POST",
params);
// Check your log cat for JSON reponse
Log.d("Single Track JSON: ", json);
try {
JSONObject jObj = new JSONObject(json);
if (jObj != null) {
DATA_F = jObj.getString("cdata");
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
这是我的PHP代码:
<?php
require 'db_connect.php';
header('Content-Type: image/jpg; charset=utf-8');
header('Content-Type: bitmap; charset=utf-8');
header('Content-Type: bitmap; charset=utf-8');
$p_category=$_REQUEST['p_category'];
$p_name=$_REQUEST['p_name'];
$p_content=$_REQUEST['p_content'];
$p_price=$_REQUEST['p_price'];
$flag["cdata"]="fail";
$flag['code']=0;
if($r=mysql_query("INSERT INTO `v_upload`(`p_category`, `p_name`, `p_content`, `p_price`) VALUES ('$p_category','$p_name','$p_content','$p_price')",$con))
{
$id = mysql_insert_id();
$binary=base64_decode($_REQUEST['prd_pic']);
header('Content-Type: bitmap; charset=utf-8');
$file = fopen('Images/Product/'.$id.'.jpg', 'wb');
// Create File
fwrite($file,$binary);
fclose($file);
$filename2='Images/Product/'.$id.'.jpg';
if(file_exists($filename2))
{
$flag["cdata"]="Sucess";
$flag['code']=1;
}
else
{
$flag["cdata"]="fail";
$flag['code']=0;
}
}
echo json_encode($flag);
mysql_close($con);
?>
错误:靠近
public void run() {
if (DATA_F.equals("Sucess")) {
alert.showAlertDialog(Upload.this, "Succes",
"Upload SucessFully", true);
java.lang.NullPointerException:尝试调用虚方法 &#39; boolean java.lang.String.equals(java.lang.Object)&#39;在null对象上 参考