用于将数据插入数据库的代码无效

时间:2018-03-25 16:26:18

标签: java android xampp

我正在将包含一些信息的图片存储在数据库中。我正在拍照。它没有插入数据,显示int.java.lang.stringlength()调用虚方法。它在最后一天工作但是当我从Xammp数据库中删除历史记录然后我运行代码时它显示错误。

 public class DoReport extends AppCompatActivity {
private EditText subject,detail;
private ImageView pic;
private Spinner  depart;
private String depat,sub,det;
//for image
private Bitmap selectedImage;
public static String image;
private Uri imageUri;
public final static int PHOTO_FROM_MEMORY_REQUESTED = 10;

@Override
protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_do_report);
        subject = (EditText) findViewById(R.id.subject);
        detail = (EditText) findViewById(R.id.detail);
        depart = (Spinner) findViewById(R.id.Depat_Edit);
    }
    //to pic the image from galery

public void imgBtn(View v) {
    Intent i = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, PHOTO_FROM_MEMORY_REQUESTED);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(requestCode == PHOTO_FROM_MEMORY_REQUESTED && resultCode == RESULT_OK){
        updateSelectedPicture(data.getData());
    }
}
private void updateSelectedPicture(Uri uri){
    try{
        imageUri = uri;
        InputStream imageStream = getContentResolver().openInputStream(imageUri);
        selectedImage = BitmapFactory.decodeStream(imageStream);
        ImageView iv = (ImageView) findViewById(R.id.ImgView);
        iv.setImageDrawable(new BitmapDrawable(selectedImage));
        image=encode(selectedImage);

    }catch(FileNotFoundException ex){

        Log.e("File not found", "Cannot find background file under received URI");
    }
}
public static String encode(Bitmap image)
{
    Bitmap immagex=image;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    immagex.compress(Bitmap.CompressFormat.JPEG, 20, baos);
    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);

    Log.e("LOOK", imageEncoded);
    return imageEncoded;
}
public void submit(View v)
{
    depat=depart.getSelectedItem().toString();
    sub=subject.getText().toString();
     det=detail.getText().toString();
    if(sub.isEmpty())
    {
        subject.setError("subject is required");
    }
   else if(det.isEmpty())
    {
        detail.setError("subject is required");
    }
    else {
        login_database(depat, sub, det, image);
    }
}
private void login_database(final String depat, final String sub,final String det,final String pic) {
    RequestQueue queue = Volley.newRequestQueue(this);
    StringRequest request = new StringRequest(Request.Method.POST, Static.user_connect,//changes required
            new Response.Listener<String>() {
                public void onResponse(String response) {
                    if ((response.contains("successful"))) {

                        Toast.makeText(DoReport.this, "Successful Submitted",Toast.LENGTH_LONG).show();
                       Intent i = new Intent (DoReport.this,UserView.class);
                        startActivity(i);
                        finish();
                    }
                    else {
                        Toast.makeText(DoReport.this, "Some error occured", Toast.LENGTH_LONG).show();//changes required
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(DoReport.this, error.toString(), Toast.LENGTH_SHORT).show();
                    Log.d("ERROR", toString());
                }
            }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {

            Map<String, String> map = new HashMap<>();
            map.put("key", "3");//changes required
            map.put("Depat", depat);
            map.put("Detail", det);
            map.put("Pic", pic);
            map.put("Subject", sub);
            map.put("U_id",Static.id);
            return map;
        }
    };
    queue.add(request);
}

0 个答案:

没有答案