when I try running the application I found the error message in logcat, NullPointerException
. Where the code which make this error is show below. The str is get from another class which is call MD5encoder
. The code show below as well. the string md 5 = MD5Encoder.encode(str)
and cursor is from the mainActiviry
. MD5encoder
is another class of a java file where I import to MainActivity
. I wonder is it the cursor where md5 = ?
, new string it cant get the str or the value so it throw a NullPointerException
. someone any idea about this ?
String md5 = MD5Encoder.encode(str);
Cursor cursor = db.rawQuery("SELECT desc FROM datatable WHERE md5 = '?' ",new String[] { md5 });
public class MD5Encoder {
public static String encode(String source){
String result = null;
try {
MessageDigest md = MessageDigest.getInstance("md5");
byte[] output = md.digest(source.getBytes());
StringBuffer sb = new StringBuffer();
for(int i=0;i<output.length;i++){
String s = Integer.toHexString(0xff&output[i]);
if(s.length()==1){
sb.append("0"+s);
}else{
sb.append(s);
}
}
result= sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return result;
}
}