gpt4 book ai didi

java - 数据库返回无法解读的代码

转载 作者:行者123 更新时间:2023-12-01 13:29:28 25 4
gpt4 key购买 nike

我的 Android 应用程序遇到问题。问题是,当我尝试从数据库中检索数据时,我得到了无法读取的代码。我是一名业余程序员,对Android编程不太了解。这是我的输出:

[com.example.foodsaver2.Food@42ae3420, 
com.example.foodsaver2.Food@42ae3720,
com.example.foodsaver2.Food@42ae3968,
com.example.foodsaver2.Food@42ae3bd0,
com.example.foodsaver2.Food@42ae3e18,
com.example.foodsaver2.Food@42ae4060,
com.example.foodsaver2.Food@42ae42a8, com.example.foodsaver2.Food@42ae4510, com.example.foodsaver2.Food@42ae4758, com.example.foodsaver2.Food@42ae49a0, com.example.foodsaver2.Food@42ae4c08, com.example.foodsaver2.Food@42ae4e50, com.example.foodsaver2.Food@42ae50b8, com.example.foodsaver2.Food@42ae5360, com.example.foodsaver2.Food@42ae55a8, com.example.foodsaver2.Food@42ae5810, com.example.foodsaver2.Food@42ae5a58, com.example.foodsaver2.Food@42ae5ca0, com.example.foodsaver2.Food@42ae5ee8, com.example.foodsaver2.Food@42ae61d0, com.example.foodsaver2.Food@42ae6418, com.example.foodsaver2.Food@42ae6660, com.example.foodsaver2.Food@42ae68c8, com.example.foodsaver2.Food@42ae6b10, com.example.foodsaver2.Food@42ae6d58, com.example.foodsaver2.Food@42ae6fa0, com.example.foodsaver2.Food@42ae7208, com.example.foodsaver2.Food@42ae7450, com.example.foodsaver2.Food@42ae7790, com.example.foodsaver2.Food@42ae79d8, com.example.foodsaver2.Food@42ae7c60, com.example.foodsaver2.Food@42ae7ea8, com.example.foodsaver2.Food@42ae8130, com.example.foodsaver2.Food@42ae8378, com.example.foodsaver2.Food@42ae85e0, com.example.foodsaver2.Food@42ae8848, com.example.foodsaver2.Food@42ae8ab0, com.example.foodsaver2.Food@42ae8d18, com.example.foodsaver2.Food@42ae8f80, com.example.foodsaver2.Food@42ae91e8, com.example.foodsaver2.Food@42ae9450, com.example.foodsaver2.Food@42ae97c0, com.example.foodsaver2.Food@42ae9a28, com.example.foodsaver2.Food@42ae9c70, com.example.foodsaver2.Food@42ae9ee0, com.example.foodsaver2.Food@42aea128, com.example.foodsaver2.Food@42aea370, com.example.foodsaver2.Food@42aea5d8, com.example.foodsaver2.Food@42aea820, com.example.foodsaver2.Food@42aeaa88, com.example.foodsaver2.Food@42aeacd0, com.example.foodsaver2.Food@42aeaf38, com.example.foodsaver2.Food@42aeb180, com.example.foodsaver2.Food@42aeb3e8, com.example.foodsaver2.Food@42aeb630, com.example.foodsaver2.Food@42aeb878, com.example.foodsaver2.Food@42aebae0, com.example.foodsaver2.Food@42aebd28, com.example.foodsaver2.Food@42aebf90, com.example.foodsaver2.Food@42aec1d8, com.example.foodsaver2.Food@42aec440, com.example.foodsaver2.Food@42aec808, com.example.foodsaver2.Food@42aeca70, com.example.foodsaver2.Food@42aeccb8, com.example.foodsaver2.Food@42aecf00, com.example.foodsaver2.Food@42aed168, com.example.foodsaver2.Food@42aed3b0, com.example.foodsaver2.Food@42aed618, com.example.foodsaver2.Food@42aed860, com.example.foodsaver2.Food@42aedaa8, com.example.foodsaver2.Food@42aedd10, com.example.foodsaver2.Food@42aedf58, com.example.foodsaver2.Food@42aee1a0, com.example.foodsaver2.Food@42aee408, com.example.foodsaver2.Food@42aee650, com.example.foodsaver2.Food@42aee8b8, com.example.foodsaver2.Food@42aeeb00, com.example.foodsaver2.Food@42aeed68, com.example.foodsaver2.Food@42aeefb0, com.example.foodsaver2.Food@42aef218, com.example.foodsaver2.Food@42aef460, com.example.foodsaver2.Food@42aef6c8, com.example.foodsaver2.Food@42aef910, com.example.foodsaver2.Food@42aefb58, com.example.foodsaver2.Food@42aefdc0, com.example.foodsaver2.Food@42af0008, com.example.foodsaver2.Food@42af0250, com.example.foodsaver2.Food@42af04b8, com.example.foodsaver2.Food@42af0700, com.example.foodsaver2.Food@42af0948, com.example.foodsaver2.Food@42af0bb0, com.example.foodsaver2.Food@42af1028, com.example.foodsaver2.Food@42af1270, com.example.foodsaver2.Food@42af14d8, com.example.foodsaver2.Food@42af1720, com.example.foodsaver2.Food@42af1968, com.example.foodsaver2.Food@42af1bd0, com.example.foodsaver2.Food@42af1e18, com.example.foodsaver2.Food@42af2060, com.example.foodsaver2.Food@42af22c8, com.example.foodsaver2.Food@42af2510, com.example.foodsaver2.Food@42af2778, com.example.foodsaver2.Food@42af29c0, com.example.foodsaver2.Food@42af2c08, com.example.foodsaver2.Food@42af2e70, com.example.foodsaver2.Food@42af30b8, com.example.foodsaver2.Food@42af3300, com.example.foodsaver2.Food@42af3568]

这是我所做的:

 public void send (View v) {
List<String> strlist = new ArrayList<String>();
strlist = mDbHelper.getAllComments();

GmailSender sender = new GmailSender("omitted", "omitted");
try {
sender.sendMail("DietWatcher Feedback",
strlist + "",
"ommited",
"omitted");
Toast.makeText(getApplicationContext(), "Sent!", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Cannot send message!", Toast.LENGTH_SHORT).show();
}
}

这是我的一些数据库代码:

public List getAllComments() {
List customers = new ArrayList();
String inputText = "";
String query =
KEY_CUSTOMER + /*"INTEGER," + */ "," +
KEY_NAME + "," +
KEY_ADDRESS1 + "," +
KEY_ADDRESS2 + "," +
KEY_CITY + "," +
KEY_STATE + "," +
KEY_ZIP + "," +
KEY_SEARCH + "," +
TOTAL_CARB + "," +
FIBER +
SUGAR +
PROTEIN+
SODIUM +
TOTALCALORIES +
FTS_VIRTUAL_TABLE +
KEY_SEARCH;
Log.w(TAG, query);
//Cursor mCursor = mDb.rawQuery(query,null);
Cursor cursor = mDb.query(FTS_VIRTUAL_TABLE, new String[]{KEY_CUSTOMER + "," +
KEY_NAME + "," +
KEY_ADDRESS1 + "," +
KEY_ADDRESS2 + "," +
KEY_CITY + "," +
KEY_STATE + "," +
KEY_ZIP + "," +
TOTAL_CARB /*+
FIBER +
SUGAR +
PROTEIN+
SODIUM +
TOTALCALORIES +
FTS_VIRTUAL_TABLE +
KEY_SEARCH */}, null, null, null, null, null);

cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Food customer = cursorToCustomer(cursor);
customers.add(customer);
cursor.moveToNext();
}
// make sure to close the cursor
cursor.close();
return customers;
}
private Food cursorToCustomer(Cursor cursor) {
Food customer = new Food();
customer.setCustomer(cursor.getString(0));
customer.setName(cursor.getString(1));
customer.setAddress1(cursor.getString(2));
customer.setAddress2(cursor.getString(3));
customer.setCity(cursor.getString(4));
customer.setState(cursor.getString(5));
customer.setZipCode(cursor.getString(6));

return customer;
}

这是 Food.java: 包 com.example.foodsaver2;

public class Food {
String customer = null;
String name = null;
String address1 = null;
String address2 = null;
String city = null;
String state = null;
String zipCode = null;
String carb = null;
String fiber = null;
String sugar = null;
String protein = null;
String sodium = null;

public String getCustomer() {
return customer;
}
public void setCustomer(String customer) {
this.customer = customer;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getCarb() {return carb;}
public void setCarb(String carb) {this.carb = carb;}
public String getFiber() {return fiber;}
public void setFiber() {this.fiber = fiber;}
public String getSugar() {return sugar;}
public void setSugar() {this.sugar = sugar;}
public String getProtein() {return protein;}
public void setProtein() {this.protein = protein;}
public String getSodium() {return sodium;}
public void setSodium() {this.sodium = sodium;}
}

那么我在这里做错了什么?任何有关此问题的帮助将不胜感激。

最佳答案

mDbHelper.getAllComments() 返回 Food 类对象的列表而不是字符串,因此响应不是可读格式。如果您想将 strlist 中的详细信息传递到 sender.sendMail,那么您需要准备另一个列表,将 strlist 中的值存储为字符串。尝试如下:

ArrayList<Food> arrallcomments = mDbHelper.getAllComments();
List<String> strlist = new ArrayList<String>();
for(Food object: list){
strlist.add("Name : "+object.getName() +
" Customer :"+object.getCustomer()+...);
}

现在使用 strlist 通过 Mail 发送 ArrayList。

关于java - 数据库返回无法解读的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21654457/

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