public abstract class AbstractIME extends InputMethodService implements
KeyboardView.OnKeyboardActionListener, CandidateView.CandidateViewListener {
...
private void clearCandidates() {
...
final dbhelper helper = new dbhelper(this);
Cursor c = helper.query();
}
...
}
public class CangjieDictionary extends WordDictionary {
private AbstractIME ime;
....
private String sortWords(char[] data) {
....
dbhelper dbh = new dbhelper(ime); ;
Cursor c = dbh.query();
}
}这里有两个类。对于第一个类是ok的,没有问题,但第二个类的代码是相同的
下面是logcat消息,为什么第二个类有空指针?
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
at com.googlecode.tcime.unofficial.dbhelper.query(dbhelper.java:50)
at com.googlecode.tcime.unofficial.CangjieDictionary.sortWords(CangjieDictionary.java:111)发布于 2013-04-16 02:08:59
在WordDictionary中声明上下文成员并创建具有上下文参数构造函数
Context mContext;
public WordDictionary(Context context)
{
mContext = context:
} 然后在CangjieDictionary中
public class CangjieDictionary extends WordDictionary {
private AbstractIME ime;
....
private String sortWords(char[] data) {
....
dbhelper dbh = new dbhelper(mContext);
Cursor c = dbh.query();
}}
https://stackoverflow.com/questions/16020201
复制相似问题