gpt4 book ai didi

java - Get 方法返回错误的空值

转载 作者:搜寻专家 更新时间:2023-11-01 09:23:33 30 4
gpt4 key购买 nike

我在 setter 中获取数据,但没有在 getter 中获取数据。下面的代码是DatabaseHelper.java的

  public  List<HouseModal> get_Working_Area_Structures_House(int limit, int offset,String searched_Str) {
if(database == null){
database = getWritableDatabase();
}
List<HouseModal> list_krd= new ArrayList<>();

String selectQuery = "SELECT DISTINCT\n" +
"\tWAS.Para_Structure_ID,\n" +
"\tWAS.Para_Code || ' ' || CAST (WAS.Structure_No AS int) AS Structure_No,\n" +
"\tST.Family_Count AS Families,\n" +
"\tFM.Family_Members_Count AS Family_Members, \n" +
"\t FM.Family_Migration AS Family_Migration\n" +
"FROM\n" +
"\t (\n" +
"\t\t SELECT\n" +
"\t\t\tP.Para_Code,\n" +
"\t\t\tPS.Para_Structure_ID,\n" +
"\t\t\tPS.Structure_No \n" +
"\t\tFROM\n" +
"\t\t\tPara_Structure AS PS\n" +
"\t\tINNER JOIN Working_Area_Structures AS WAS ON PS.Para_Structure_ID = WAS.Para_Structure_ID\n" +
"\t\tINNER JOIN Field_Station_Paras AS P ON PS.Para_ID = P.Para_ID \n" +
"\t) AS WAS,\n" +
"\t (\n" +
"\tSELECT\n" +
"\t\t\tKH.Para_Structure_ID,\n" +
"\t\t\tCOUNT(DISTINCT KH.House_Hold_ID) AS Family_Count \n" +
"\t\tFROM\n" +
"\t\t\tKhandan_Register_Header AS KH\n" +
"\t\tLEFT JOIN Family_Visit_History AS FVH ON KH.House_Hold_ID = FVH.House_Hold_ID \n" +
"\t\tWHERE\n" +
"\t\t(FVH.Visit_Status = 0 OR FVH.Visit_Status IS NULL)\n" +
"\t\t--AND ((date(FVH.Visit_Date) >= (SELECT date(Starting_Date) FROM Working_Cycle WHERE DATE('NOW') BETWEEN date(Starting_Date)AND date(Ending_Date)) AND date(FVH.Visit_Date) <= (SELECT date(Ending_Date) FROM Working_Cycle WHERE DATE('NOW') BETWEEN date(Starting_Date)AND date(Ending_Date))) OR date(FVH.Visit_Date) IS NULL) \n" +
"\t\t--AND (KH.House_Hold_ID NOT IN (SELECT DISTINCT House_Hold_ID FROM Family_Visit_History WHERE Visit_Status = 1)) \n" +
"\t\tGROUP BY KH.Para_Structure_ID\n" +
"\t) AS ST , (\n" +
"\t\t SELECT\n" +
"\t\t\tKH.Para_Structure_ID,\n" +
"\t\t\tCOUNT(\n" +
"\t\t\t\tDISTINCT KD.Family_Member_ID\n" +
"\t\t\t) AS Family_Members_Count, \n" +
"\t\t\tfmr.Family_Migration_ID AS Family_Migration \n" +
"\t\tFROM\n" +
"\t\t\tKhandan_Register_Detail AS KD\n" +
"\t\tINNER JOIN Khandan_Register_Header AS KH ON KD.House_Hold_ID = KH.House_Hold_ID\n" +
"\t\tLEFT JOIN Family_Visit_History AS FVH ON KH.House_Hold_ID = FVH.House_Hold_ID \n" +
"\t\tleft join Family_Migration_Register as fmr on KH.House_Hold_ID = fmr.House_Hold_ID \n" +
"\t\tWHERE\n" +
"\t\t\t(\n" +
"\t\t\t\tFVH.Visit_Status = 0\n" +
"\t\t\t\tOR FVH.Visit_Status IS NULL\n" +
"\t\t\t) \n" +
"\t\t--AND ((date(FVH.Visit_Date) >= (SELECT date(Starting_Date)FROM Working_Cycle WHERE DATE('NOW') BETWEEN date(Starting_Date)AND date(Ending_Date)) \n" +
"\t\t--AND date(FVH.Visit_Date) <= (SELECT date(Ending_Date) FROM Working_Cycle WHERE DATE('NOW') BETWEEN date(Starting_Date)AND date(Ending_Date))) OR date(FVH.Visit_Date) IS NULL) \n" +
"\t\tAND (KH.House_Hold_ID NOT IN (SELECT DISTINCT House_Hold_ID FROM Family_Visit_History WHERE Visit_Status = 1 )) \n" +
"\t\tGROUP BY\n" +
"\t\t\tKH.Para_Structure_ID \n" +
"\t) AS FM \n" +
"WHERE\n" +
"\tWAS.Para_Structure_ID = ST.Para_Structure_ID \n" +
"\n" +
"AND WAS.Para_Structure_ID = FM.Para_Structure_ID\n" +
"\n" +
"AND ST.Para_Structure_ID = FM.Para_Structure_ID\n" +
"\n";
if (!searched_Str.trim().equals("null") && !searched_Str.trim().equals(""))
{
selectQuery += " And WAS.Structure_No like '%"+searched_Str+"%'";
}
selectQuery += " ORDER BY WAS.Para_Code, Cast(WAS.Structure_No As int) limit "+limit+" offset "+offset;

try{
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.getCount() > 0) {
if (cursor != null && cursor.moveToFirst()) {
do {
HouseModal dkrd = new HouseModal();
dkrd.setStructureID(cursor.getInt(0));
dkrd.setStructureNo(cursor.getString(1));
dkrd.setFamilies(cursor.getInt(2));
dkrd.setMembers(cursor.getInt(3));
dkrd.setFamilyMigrationID(cursor.getString(4));
list_krd.add(dkrd);
} while (cursor.moveToNext());
}
}
cursor.close();
}
catch (Exception e){
e.printStackTrace();
}
return list_krd;
}

我在 setFamilyMigrationID 中得到结果集,如您在屏幕截图中所见 1

但在 adpater 中设置的 getter 中没有得到结果

package pk.softech.sukh.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import pk.softech.sukh.R;
import pk.softech.sukh.modal.HouseModal;

public class HouseAdapter extends ArrayAdapter<HouseModal> {

private View root;

public HouseAdapter(Context context,List<HouseModal> items) {
super(context,R.layout.view_house_item);
}

class ViewHolder{
TextView totalAfrad,totalKhandan,structureID,migratedFamilies;
}

@Override
public View getView(int position, View view, ViewGroup parent) {
ViewHolder holder;

HouseModal item = getItem(position);
if(view == null){
view = LayoutInflater.from(getContext()).inflate(R.layout.view_house_item,null);
holder = new ViewHolder();
holder.structureID = (TextView) view.findViewById(R.id.structureID);
holder.totalAfrad = (TextView) view.findViewById(R.id.totalAfrad);
holder.totalKhandan = (TextView) view.findViewById(R.id.totalKhandan);
holder.migratedFamilies = (TextView) view.findViewById(R.id.families);

view.setTag(holder);
}
else{
holder = (ViewHolder) view.getTag();
}

holder.structureID.setText(String.valueOf(item.getStructureNo()));
holder.totalKhandan.setText(String.valueOf(item.getFamilies()));
holder.totalAfrad.setText(String.valueOf(item.getMembers()));
holder.migratedFamilies.setText(String.valueOf(item.getFamilyMigrationID()));

return view;
}
}

但是我没有在 getFamilyMigrationID 中得到结果集,正如您在屏幕截图中看到的那样 2

模态代码如下

package pk.softech.sukh.modal;

public class HouseModal {

private int structureID, families,members;
private String migrationID;

private String houseHoldID;
private String structureNo ;


public String getFamilyMigrationID() {
return migrationID;
}

public void setFamilyMigrationID(String migrationID) {
this.migrationID = migrationID;
}

public String getStructureNo() {
return structureNo;
}

public void setStructureNo(String structureNo) {
this.structureNo = structureNo;
}


public int getStructureID() {
return structureID;
}

public void setStructureID(int structureID) {
this.structureID = structureID;
}

public int getFamilies() {
return families;
}

public void setFamilies(int families) {
this.families = families;
}

public int getMembers() {
return members;
}

public void setMembers(int members) {
this.members = members;
}

public String getHouseHoldID() {
return houseHoldID;
}

public void setHouseHoldID(String houseHoldID) {
this.houseHoldID = houseHoldID;
}
}

最佳答案

你需要将 listItem 设置为 super() 方法尝试下面的代码它会解决你的问题

public HouseAdapter(Context context,List<HouseModal> items) {
super(context,R.layout.view_house_item,items);
}

关于java - Get 方法返回错误的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52625849/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com