Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 自定义SimpleCursorAdapter以解码值_Android_Sqlite - Fatal编程技术网

Android 自定义SimpleCursorAdapter以解码值

Android 自定义SimpleCursorAdapter以解码值,android,sqlite,Android,Sqlite,我尝试自定义SimpleCrsorAdapter来解码一个值并设置为textview,但不起作用 我的自定义simplecursoradapter类: public class simpledecode extends SimpleCursorAdapter{ private NotesDbAdapter mDbHelper; public simpledecode(Context context, int layout, Cursor c, String[] from, in

我尝试自定义SimpleCrsorAdapter来解码一个值并设置为textview,但不起作用

我的自定义simplecursoradapter类:

public class simpledecode extends SimpleCursorAdapter{

private NotesDbAdapter mDbHelper;
public simpledecode(Context context, int layout, Cursor c, String[] from,
        int[] to) {
    super(context, layout, c, from, to);
}
@Override
public void setViewText(TextView v, String text) {
    // TODO Auto-generated method stub
    super.setViewText(v, text);
    v.setText(mDbHelper.base64toString(text));
}
我的解码方法:

public String base64toString(String text) 
{
    byte[] data1 = Base64.decode(text, Base64.DEFAULT);
    String text1 = null;
    try {
        return text1 = new String(data1, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
}

这是因为行
byte[]data1=Base64.decode(text,Base64.DEFAULT)中的文本为空

您可以在方法的开头添加空检查

public String base64toString(String text) 
{
    if (text == null) return null;

    byte[] data1 = Base64.decode(text, Base64.DEFAULT);
    String text1 = null;
    try {
        return text1 = new String(data1, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
}

你能说得更具体些吗?到底是什么不起作用?com.example.note.simpledecode.setViewText(simpledecode.java:24)上的java.lang.NullPointerException我想textview或text可能是nullv.setText(mDbHelper.base64toString(text));已尝试此代码,请查看是否引发了任何异常?v、 setText(“+mDbHelper.base64toString(text));将“+”添加到setViewText方法上的v.setText中我尝试了,但它不是null。我认为如果文本为空,那么文本的解码也是空的。所以不需要if(text==null)返回null;我试图将空值传递到
Base64.decode
中,但它抛出了一个异常。