마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

DB에서 데이터 조회후 listView(여기서는 customerListView)에 뿌릴려고 하는데 에러가 납니다

0 추천

 

ChartActivity .java
public class ChartActivity extends Activity implements OnClickListener{

    String TAG = "ChartActivity";

    EditText customer_name;
    EditText customer_phone;
    Button btnHome;
    Button btnBack;
    Button btn_search_customer;
    ListView customerListView;
    TextView customer_id_chart;
    TextView customer_name_chart; 
    TextView customer_jumin_chart;
    TextView customer_phone_chart;
    TextView customer_medical_chart;
    TextView customer_etc_chart;    //고객 기타메모사항

    ArrayList<HashMap<String,Object>> listData;

    CustomerListAdapter customerListAdapter;

    Context mContext;
    customerFine mTask;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_chart);
        super.onCreate(savedInstanceState);

        mContext = this;
        customer_name = (EditText)findViewById(R.id.customer_name);
        customer_phone = (EditText)findViewById(R.id.customer_phone);

        btnHome = (Button)findViewById(R.id.btnHome);
        btnBack = (Button)findViewById(R.id.btnBack);
        btn_search_customer = (Button)findViewById(R.id.btn_search_customer);
        btn_search_customer.setOnClickListener(this);

        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplication(), MainActivity.class);
                startActivity(intent);
            }
        });
        btnHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplication(), MainActivity.class);
                startActivity(intent);
            }
        });
    }
    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.btn_search_customer:
                mTask = new customerFine();
                mTask.execute();

                break;
        }
    }

    class customerFine extends AsyncTask<String,Void, ArrayList<HashMap<String, Object>>>{

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected ArrayList<HashMap<String, Object>> doInBackground(String... params) {

            ResultSet reset = null;
            Connection conn = null;

            String where = "";
            String search_name = customer_name.getText().toString();
            String search_phone = customer_phone.getText().toString();
            if(!("").equals(search_name)){
                where += "and name like '%"+search_name+"%' ";
            }
            if(!("").equals(search_phone)){
                where += "and mobile like '%"+search_phone+"%' ";
            }
            String query = "쿼리" ;
            HashMap<String, String> listMap = new HashMap<String, String>();

            try {
                Class.forName("net.sourceforge.jtds.jdbc.Driver");
                conn = DriverManager.getConnection("DB정보");
                Statement stmt = conn.createStatement();

                reset = stmt.executeQuery(query);

                ResultSetMetaData rsmd =  reset.getMetaData();

                int columnsCount = rsmd.getColumnCount();

                listData = new ArrayList<HashMap<String,Object>>();


                while(reset.next()){
                    if ( isCancelled() ) break;

                    HashMap<String, Object> row = new HashMap<String, Object>(columnsCount);

                    for(int i=1;i<=columnsCount;++i){
                        row.put(rsmd.getColumnName(i),reset.getObject(i));
                    }
                    listData.add(row);
                }
                conn.close();

            }
            catch (Exception e)
            {
                Log.w("DB Error connection", "" + e.getMessage());
            }

            return listData;
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate();
        }

        protected void onPostExecute(ArrayList<HashMap<String, Object>> list){
            reflesh();
        }
        @Override
        protected void onCancelled(){
            super.onCancelled();
        }
    }
    public void reflesh(){
        this.customerListAdapter = new CustomerListAdapter(this, R.layout.customer_list_adapter, listData);
        this.customerListView.setAdapter(customerListAdapter);
        this.customerListAdapter.notifyDataSetChanged();
    }
}
CustomerListAdapter .java
public class CustomerListAdapter extends BaseAdapter {
   
   String TAG = "CustomerListAdapter";
   
   Context mContext;
   LayoutInflater Inflater;
   ArrayList<HashMap<String, Object>> customerListData = new ArrayList<HashMap<String, Object>>();
   int layout;
   
   public CustomerListAdapter (Context context, int alayout, ArrayList<HashMap<String, Object>> customerList) {
      
      mContext = context;
      Inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      layout = alayout;
      customerListData = customerList;
   }  // MyListAdapter

   @Override
   public int getCount() {
      return customerListData.size();
   }

   @Override
   public String getItem(int position) {
      //return cardListData.get(position).get("p_date");
      return customerListData.get(position).toString(); 
   }

   @Override
   public long getItemId(int position) {
      // TODO Auto-generated method stub
      return position;
   }
   


   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
      
      final int pos = position;
         
      if (convertView == null) {
         convertView = Inflater.inflate(layout, parent, false);
      }  // if

      TextView customer_chart_id = (TextView)convertView.findViewById(R.id.customer_chart_id);
      customer_chart_id.setTextColor(Color.BLACK);
      customer_chart_id.setText(customerListData.get(position).get("chart_id").toString());

      TextView customer_chart_name = (TextView)convertView.findViewById(R.id.customer_chart_name);
      customer_chart_name.setTextColor(Color.BLACK);
      customer_chart_name.setText(customerListData.get(position).get("name").toString());

      TextView customer_chart_jumin = (TextView)convertView.findViewById(R.id.customer_chart_jumin);
      customer_chart_jumin.setTextColor(Color.BLACK);
      customer_chart_jumin.setText(customerListData.get(position).get("jumin").toString());

      TextView customer_chart_phone = (TextView)convertView.findViewById(R.id.customer_chart_phone);
      customer_chart_phone.setTextColor(Color.BLACK);
      customer_chart_phone.setText(customerListData.get(position).get("mobile").toString());

      TextView customer_chart_medical = (TextView)convertView.findViewById(R.id.customer_chart_medical);
      customer_chart_medical.setTextColor(Color.BLACK);
      customer_chart_medical.setText(customerListData.get(position).get("procedure_name").toString());

      TextView customer_chart_etc = (TextView)convertView.findViewById(R.id.customer_chart_etc);
      customer_chart_etc.setTextColor(Color.BLACK);
      customer_chart_etc.setText(customerListData.get(position).get("remark").toString());

      return convertView;
   }  // getView
 
 
소스는 위와같고 에러 메세지는 아래와같이 뜹니다.
왜그런걸까요...getView 또한 호출돼지않습니다.TT
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
REDORI (350 포인트) 님이 2018년 1월 9일 질문
REDORI님이 2018년 1월 9일 수정

1개의 답변

+1 추천
 
채택된 답변
protected void onCreate(Bundle savedInstanceState) {
	...
	customerListView = (ListView)findViewById(R.id.(list_view_id));
	...
}

윗 내용이 빠진거 같네요.

디자이너정 (42,810 포인트) 님이 2018년 1월 9일 답변
REDORI님이 2018년 1월 9일 채택됨
-ㅇ- 저런...기본적인게 빠져있네요..TT 감사합니다~
...