程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> bitmapfactory-android listview適配器的錯誤

bitmapfactory-android listview適配器的錯誤

編輯:編程綜合問答
android listview適配器的錯誤

具體報錯見下面。高手求解決·····
先貼代碼,下面是PointMgrActivity.java

package com.app.bluetoothpro;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.app.DB.DBManager;
import com.app.DB.PointClass;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class PointMgrActivity extends Activity {

protected static final String ACTIVITY_TAG = "LogDemo";
private DBManager dbManager;
public SQLiteDatabase db;
String gID;
String pStatu;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.point_mgr);
    dbManager = new DBManager(this);

    /*
     * Points person = new Points(); person.pid = "id1"; person.pstatu =
     * "OFF"; db.execSQL("INSERT INTO points VALUES (?, ?)", new
     * Object[]{person.pid, person.pstatu});
     */
    addbtn();
}

/********************************* 添加add方法 ****************************************/
public void add() {
    ArrayList<PointClass> persons = new ArrayList<PointClass>();

    PointClass person = new PointClass(gID, pStatu);

    persons.add(person);
    dbManager.add(persons);
}

 *  */***************************** 添加query()查詢方法 ******************************/
public void query() {
    List<PointClass> persons = dbManager.query();
    ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
    for (PointClass person : persons) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", person.pid);
        map.put("pstatu", getstatu(pStatu));
        listItem.add(map);
        Log.d(ACTIVITY_TAG, person.pid + " +++++++++++++++++++++++++++ "
                + getstatu(pStatu));
    }
    ListView list = (ListView) findViewById(R.id.pointListView);
    SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem,
            R.layout.point_mgr_list_item,
            new String[] { "pointsID", "pointsStatu" },
            new int[] { R.id.pointsID, R.id.pointsStatu });
    list.setAdapter(listItemAdapter);

    list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
        }
    });
}
private Object getstatu(String str) {
    // TODO Auto-generated method stub
    if (str.equals("ON")) {
        return R.drawable.led_green;
    } else {
        return R.drawable.led_red;
    }
}*  * 

/************************* 為添加按鈕添加事件 **************************/

void addbtn() {
    ImageButton ib_add = (ImageButton) findViewById(R.id.addpoint);
    ib_add.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            LayoutInflater inflater = getLayoutInflater();
            final View layout = inflater.inflate(R.layout.add_dialog,
                    (ViewGroup) findViewById(R.id.dialog));
            new AlertDialog.Builder(PointMgrActivity.this)
                    .setTitle("請添加節點")
                    .setView(layout)
                    .setPositiveButton("確定",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    EditText et = (EditText) layout
                                            .findViewById(R.id.addID);
                                    gID = et.getText().toString();
                                    pStatu = "OFF";
                                    /***************************************** 將輸入的id,狀態寫入map中 **************/
                                    Log.i(PointMgrActivity.ACTIVITY_TAG,
                                            gID + "   " + pStatu);
                                    // insert(db,gID,pStatu);
                                    // close(db);
                                    add();
                                    query();

                                    /******************** 調試代碼 ********************************************/
                                    Log.i(PointMgrActivity.ACTIVITY_TAG,
                                            gID);
                                    /***************************************************************************************/

                                }
                            })
                    .setNegativeButton("取消",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {

                                }
                            }).show();
        }

    });

}

}

layout.xml布局文件中有listview,有 兩列textview imageview ,
上面query()方法是將從sqlite查詢的數據在listview顯示,下面是適配器代碼:
ListView list = (ListView) findViewById(R.id.pointListView);
SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem,
R.layout.point_mgr_list_item,
new String[] { "pointsID", "pointsStatu" },
new int[] { R.id.pointsID, R.id.pointsStatu });
list.setAdapter(listItemAdapter);
log調試得到正確從數據庫查詢數據,就是不listview顯示數據.
運行報錯:
10-23 10:56:36.670: E/BitmapFactory(12701): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)

最佳回答:


適配器參數寫錯了
SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem, R.layout.point_mgr_list_item, new String[] { "pid", "pstatu" }, new int[] { R.id.pointsID, R.id.pointsStatu }); list.setAdapter(listItemAdapter);

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved