我有一个String图像路径,它具有所选图像的路径。如果用户选择图像,我必须在服务器上传它。我想检查一下imagepath是否为空。我已经尝试过,但它给NullPointerException
。图像路径中的NullPointerException
这是我的代码。
public String imagepath = null;
public String imagepath1 = null;
,我检查,如果它是空的:
Log.e("imagepath",""+imagepath);
Log.e("imagepath1", ""+imagepath1);
if (imagepath.equals(null)){
Log.e("no image path","dfdsfdsfdsfdsfdf");
}
else {
uploadFile(imagepath);
}
if (imagepath1.equals(null)){
Log.e("no imagepath1 path","imagepath1");
}
else {
uploadFile2(imagepath);
}
如果我不选择任何图片,它显示了NullPointerException
。请帮帮我。这里有什么问题。
' TextUtils.isEmpty'会为你做到这一点 –
@ cricket_007是的,你是对的.. –