0

我收到 NullPointerException: println 尝试启动活动时需要消息错误。我看不到错误。

这是我关于错误的数据库

public HashMap<String, String> getsaleInfo(String saleId) {
    HashMap<String, String> wordList = new HashMap<String, String>();
    SQLiteDatabase database = this.getReadableDatabase();
    String selectQuery = "SELECT * FROM SUPERSALE where supersaleId='"+saleId+"'";
    Cursor cursor = database.rawQuery(selectQuery, null);
    if (cursor.moveToFirst()) {
        do {
                //HashMap<String, String> map = new HashMap<String, String>();
            wordList.put("saleCust", cursor.getString(1));
            wordList.put("saleName", cursor.getString(2));
            wordList.put("saleTime", cursor.getString(4));
            wordList.put("saleTax", cursor.getString(5));
            wordList.put("saleNotes", cursor.getString(6));
               //wordList.add(map);
        } while (cursor.moveToNext());
    }                   
return wordList;
}

这是我在活动中检索的方式

        saleCust = (TextView) findViewById(R.id.saleCust);
        saleNotes = (TextView) findViewById(R.id.saleNotes);
        saleName = (TextView) findViewById(R.id.saleName);
        saleTime = (TextView) findViewById(R.id.saleTime);
        saleTax = (TextView) findViewById(R.id.saleTax);

Intent objIntent = getIntent();
        String saleId = objIntent.getStringExtra("supersaleId");
        Log.d("Reading: ", "Reading all contacts..");
        HashMap<String, String> saleList = controller.getsaleInfo(saleId);
        Log.d("saleCust",saleList.get("saleCust"));
        Log.d("saleName",saleList.get("saleName"));
        Log.d("saleTime",saleList.get("saleTime"));
        Log.d("saleTax",saleList.get("saleTax"));
        Log.d("saleNotes",saleList.get("saleNotes"));

        if(saleList.size()!=0) {
            saleCust.setText(saleList.get("saleCust"));
            saleName.setText(saleList.get("saleName"));
            saleTime.setText(saleList.get("saleTime"));
            saleTax.setText(saleList.get("saleTax"));
            saleNotes.setText(saleList.get("saleNotes"));

        }}      

错误来自线路

Log.d("saleCust",saleList.get("saleCust"));
4

1 回答 1

1

请在下次发布您的 logcat 和您的 UI 活动。由于您的布局中有 textview,您可以使用 Listview、ExpandedListView 等。如果是这样,android 视图要求您的表中有一个列 _id 并在您的查询中检索,以便视图可以与通过 _id 列从数据库游标中获取数据适配器的数据。

希望这可以帮助。

于 2013-07-30T20:20:46.413 回答