Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.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 sql DB适配器不断崩溃_Android_Sql_Adapter - Fatal编程技术网

android sql DB适配器不断崩溃

android sql DB适配器不断崩溃,android,sql,adapter,Android,Sql,Adapter,我使用以下代码使用适配器查询数据库 db = new DBAdapter(this); db.open(); String strname = roomid; Cursor c = db.getAsset(strname); if (c.moveToFirst()) DisplayContact(c); db.close(); 我的问题是在我使用它的课堂上,我得到了错误 构造函数DBAdapter(SubsamplingScale

我使用以下代码使用适配器查询数据库

db = new DBAdapter(this);
    db.open();
    String strname = roomid;
    Cursor c = db.getAsset(strname);
    if (c.moveToFirst())        
        DisplayContact(c);
db.close();
我的问题是在我使用它的课堂上,我得到了错误

构造函数DBAdapter(SubsamplingScaleImageView)未定义

唯一能阻止此错误的方法是在() 但是,当运行导致应用程序崩溃并出现空指针异常时,会发生此情况

有人能帮助我理解运行查询需要定义什么吗

如果我在我的主要活动中插入上面的代码,它工作得很好,但是我使用它的类设置如下

公共类子采样ScaleImageView扩展了视图实现OnTouchListener{

谢谢你的帮助

标记

更新 尝试了以下操作,但仍出现空指针异常

    this.context = context.getApplicationContext();
    db = new DBAdapter(this.context);
    db.open();
    String strname = roomid;
    Cursor c = db.getAsset(strname);
    if (c.moveToFirst())        
        DisplayContact(c);
    db.close();
谢谢


标记

由于SubsamplingScaleImageView不是上下文类,因此需要为其提供上下文。显然,您是通过以下方式获得SubsamplingScaleImageView类中的上下文:

Context context;
SubsamplingScaleImageView(Context context) {
    this.context = context; // this is the context you need to pass - not an instance of the ImageView class
}
db = new DBAdapter(context);
现在,请执行以下操作:

Context context;
SubsamplingScaleImageView(Context context) {
    this.context = context; // this is the context you need to pass - not an instance of the ImageView class
}
db = new DBAdapter(context);

您不应该使用getApplicationContext()除非你真的知道你在做什么。同样在这个时候,我假设你在调用SubsamplingImageView构造函数时正在传递活动或在活动中获得的上下文。

你可能需要给它一个上下文,而你的SubsamplingScaleImageView不是。谢谢你的任何想法。我对这个T非常陌生他不是activitydb=new DBAdapter(上下文)类;在空指针异常中工作但仍会崩溃该应用程序。上下文是使用公共子采样ScaleImageView(上下文上下文)设置的{super(上下文);this.context=context;}Sunil构造函数中已经以公共子采样ScaleImageView的形式存在(Context-Context,AttributeSet-attr){super(Context,attr);this.Context=Context;}当我使用db=new-DBAdapter(Context)调用它时,它仍然给我一个null-pinter异常这里类的完整代码我在public-void-finditem(String-roomid)处有错误{