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