public class CocktailIndexActivity extends Activity{

             NetworkXMLActivity ab = new NetworkXMLActivity();

             public void onCreate(Bundle savedInstanceState){

                           super.onCreate(savedInstanceState);

                           setContentView(R.layout.main);

                           loadList();

             }

            

             public void reLoadList(View view){

                           loadList();

             }

            

             public void reLoadList1(View view){

                           ab.loadList();

                          

             }

            

             HashMap<String, String> hm = new HashMap<String, String>();

             public void loadList(){

                           String theUrl = "http://tierro.cafe24.com/cok/list1.xml";

                           cmsHTTP cmshttp = new cmsHTTP();

                           cmshttp.encoding = "UTF-8";

                           cmshttp.act = this;

                           String tmpData = cmshttp.sendGet(theUrl);

                           if(tmpData==null) return;

                           hm = xml2HashMap(tmpData, "UTF-8");

                           theListAdapter listAdapter = new theListAdapter(this, R.layout.list_row1, hm);

                           ListView listView = (ListView) findViewById(R.id.listView1);

                           listView.setAdapter(listAdapter);

             }

 

 

             public HashMap<String, String> xml2HashMap(String tmpData, String encoding){

                           HashMap<String, String> hm = new HashMap<String, String>();

                           hm.put("count", "0");

                           try{

                                        DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();

                                        DocumentBuilder docB = docBF.newDocumentBuilder();

                                        InputStream is = new ByteArrayInputStream(tmpData.getBytes(encoding));

                                        Document doc = docB.parse(is);

                                        Element lists = doc.getDocumentElement();

                                        NodeList dataList = lists.getElementsByTagName("data");

                                        int c = 0;

                                        for(int i = 0; i<dataList.getLength(); i++){

                                                     NodeList dataNodeList = dataList.item(i).getChildNodes();

                                                     for(int j=0; j<dataNodeList.getLength(); j++){

                                                                  Node itemNode = dataNodeList.item(j);

                                                                  if(itemNode.getFirstChild() != null){

                                                                                String nodeName = itemNode.getNodeName();

                                                                                String nodeValue = itemNode.getFirstChild().getNodeValue();

                                                                                hm.put(nodeName + "[" + i + "]", nodeValue);

                                                                  }

                                                     }

                                                     c++;

                                        }

                                        hm.put("count", Integer.toString(c));

                           }catch (Exception e){

                                        Log.e("com.cms.sample.xml2HashMap", e.getMessage());

                           }

                           return hm;

             }

            

             class theListAdapter extends BaseAdapter{

                          

                           LayoutInflater inflater;

                           HashMap<String, String>hm;

                           Context mContext;

                           int mListLayout;

                           public int listCount = 0;

                          

                           public theListAdapter(Context tContext, int listLayout, HashMap

                                        <String, String>tmpHm){

                                                     mContext = tContext;

                                                     mListLayout = listLayout;

                                                     hm = tmpHm;

                                                     inflater = (LayoutInflater)mContext.

                                                                                getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                                                     listCount = Integer.parseInt(hm.get("count").toString());

             }

 

                           public theListAdapter(NetworkXMLActivity networkXMLActivity,

                                                     int listRow1, HashMap<String, String> hm2) {

                                        // TODO Auto-generated constructor stub

                           }

 

                           public int getCount() {

                                        // TODO Auto-generated method stub

                                        return listCount;

                           }

 

                           public Object getItem(int arg0) {

                                        // TODO Auto-generated method stub

                                        return arg0;

                           }

 

                           public long getItemId(int position) {

                                        // TODO Auto-generated method stub

                                        return position;

                           }                        

                          

                           public HashMap<String, Bitmap>hmImg= new HashMap<String, Bitmap>();

                          

                           public View getView(int position, View convertView, ViewGroup parent) {

                                        if(convertView == null){

                                                     convertView = inflater.inflate(mListLayout, parent, false);

                                        }

                                       

                                        try{

                                                     if(hmImg.get("thumb[" + position + "]") == null){

                                                                   String urlstr = hm.get("thumb[" + position + "]");

                                                                  URL url = new URL("urlstr);

                                                                  URLConnection conn = url.openConnection();

                                                                  conn.connect();

                                                                  BufferedInputStream bis = new BufferedInputStream(conn.

                                                                                             getInputStream(), 512 * 1024);

                                                                   Bitmap bm = BitmapFactory.decodeStream(bis);

                                                                  bis.close();

                                                                  hmImg.put("thumb[" + position + "]", bm);

                                                     }

                                                     if (hmImg.get("thumb[" + position + "]") != null){

                                                                  ((ImageView) convertView.findViewById(R.id.imageView1))

                                                                                             .setImageBitmap(hmImg.get("thumb[" + position + "]"));

                                                     }

                                        }catch (IOException e){}

                                       

                                        ((TextView) convertView.findViewById(R.id.textView1))

                                        .setText("["+hm.get("rowid["+position+"]")+"]"

                                                                  + hm.get("subject["+position+"]"));

                                        ((TextView) convertView.findViewById(R.id.textView2))

                                        .setText(hm.get("contents["+position+"]"));

                                       

                                        final int positionInt = position;

                                        ((LinearLayout) convertView.findViewById(R.id.linealayout1))

                                        .setOnClickListener(new Button.OnClickListener(){

                                                     public void onClick(View v){

                                                                  detailInfo(positionInt);

                                                     }

                                        });

                                        return convertView;

                           }

 

                           protected void detailInfo(int position) {

                                        Dialog dialog = new Dialog(mContext);

                                        dialog.setContentView(R.layout.detail);

                                        dialog.setTitle(hm.get("rowid["+position+"]"));

                                        dialog.show();

                                       

                                        ((TextView) dialog.findViewById(R.id.textView1))

                                                                  .setText(hm.get("subject[" + position + "]"));

                                        ((TextView) dialog.findViewById(R.id.textView2))

                                                                  .setText(hm.get("contents[" + position + "]"));

                                        ((TextView) dialog.findViewById(R.id.textView3))

                                        .setText(hm.get("make["+position+"]"));

                                        ((TextView) dialog.findViewById(R.id.textView4))

                                        .setText(hm.get("taste["+position+"]"));

                                       

                                        Button buttonOK = (Button) dialog.findViewById(R.id.button1);

                                        buttonOK.setOnClickListener(new detailOKListener(dialog));

                                       

                                        try{

                                                     if (hm.get("img[" + position + "]") != null){

                                                                  String urlstr = hm.get("img[" + position + "]");

                                                                  URL url = new URL("urlstr);

                                                                  URLConnection conn = url.openConnection();

                                                                  conn.connect();

                                                                  BufferedInputStream bis = new BufferedInputStream(conn

                                                                                             .getInputStream(), 512 * 1024);

                                                                  Bitmap bm = BitmapFactory.decodeStream(bis);

                                                                  ((ImageView) dialog.findViewById(R.id.imageView1))

                                                                               .setImageBitmap(bm);                                                          

                                                     }

                                        }catch (IOException e){}

                           }

                          

                           protected class detailOKListener implements OnClickListener{

                                        private Dialog dialog;

                                        public detailOKListener(Dialog dialog){

                                                     this.dialog = dialog;

                                        }

                                        public void onClick(View v) {

                                                     dialog.dismiss();

                                                    

                                        }

                           }

 

                          

             }

}


==================================================================================================================

(import 부분은 길어서 생략했습니다.)

이런 식인데 첫번째 버튼 (reLoadList)를 누르면 잘 작동됩니다. 하위 소스까지.

그런데 다른 버튼을 누르면 다른 xml을 불러오고 싶어서 두번째 버튼(reLoadList1)에 

xml주소만 다르게 하고 전부 똑같이 작성 한 소소(NetworkXMLActivity)를 만든뒤 

ab(NetworkXMLActivity ab = new NetworkXMLActivity();)로 변환해 loadList 매소드를 작성하고 두번째 버튼을 누르면 계속 오류가 나네요 ㅠㅠ


답변 부탁드릴게요 ㅠㅠ


로그 추가합니다.


===================================================================================================================


05-30 08:57:24.720: D/dalvikvm(341): GC_FOR_MALLOC freed 1039K, 57% free 2831K/6535K, external 2089K/2137K, paused 106ms

05-30 08:57:24.948: D/dalvikvm(341): GC_FOR_MALLOC freed 724K, 60% free 2650K/6535K, external 2081K/2137K, paused 86ms

05-30 08:57:25.178: D/dalvikvm(341): GC_FOR_MALLOC freed 542K, 60% free 2650K/6535K, external 2093K/2137K, paused 81ms

05-30 08:57:25.470: D/dalvikvm(341): GC_FOR_MALLOC freed 542K, 60% free 2651K/6535K, external 2106K/2137K, paused 117ms

05-30 08:57:26.348: D/dalvikvm(341): GC_EXTERNAL_ALLOC freed 549K, 60% free 2639K/6535K, external 2118K/2137K, paused 390ms

05-30 08:57:36.848: D/dalvikvm(341): GC_CONCURRENT freed 338K, 55% free 2997K/6535K, external 2159K/2671K, paused 26ms+35ms

05-30 08:57:36.982: D/AndroidRuntime(341): Shutting down VM

05-30 08:57:36.988: W/dalvikvm(341): threadid=1: thread exiting with uncaught exception (group=0x40015560)

05-30 08:57:37.028: E/AndroidRuntime(341): FATAL EXCEPTION: main

05-30 08:57:37.028: E/AndroidRuntime(341): java.lang.IllegalStateException: Could not execute method of the activity

05-30 08:57:37.028: E/AndroidRuntime(341): at android.view.View$1.onClick(View.java:2144)

05-30 08:57:37.028: E/AndroidRuntime(341): at android.view.View.performClick(View.java:2485)

05-30 08:57:37.028: E/AndroidRuntime(341): at android.view.View$PerformClick.run(View.java:9080)

05-30 08:57:37.028: E/AndroidRuntime(341): at android.os.Handler.handleCallback(Handler.java:587)

05-30 08:57:37.028: E/AndroidRuntime(341): at android.os.Handler.dispatchMessage(Handler.java:92)

05-30 08:57:37.028: E/AndroidRuntime(341): at android.os.Looper.loop(Looper.java:123)

05-30 08:57:37.028: E/AndroidRuntime(341): at android.app.ActivityThread.main(ActivityThread.java:3683)

05-30 08:57:37.028: E/AndroidRuntime(341): at java.lang.reflect.Method.invokeNative(Native Method)

05-30 08:57:37.028: E/AndroidRuntime(341): at java.lang.reflect.Method.invoke(Method.java:507)

05-30 08:57:37.028: E/AndroidRuntime(341): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

05-30 08:57:37.028: E/AndroidRuntime(341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

05-30 08:57:37.028: E/AndroidRuntime(341): at dalvik.system.NativeStart.main(Native Method)

05-30 08:57:37.028: E/AndroidRuntime(341): Caused by: java.lang.reflect.InvocationTargetException

05-30 08:57:37.028: E/AndroidRuntime(341): at java.lang.reflect.Method.invokeNative(Native Method)

05-30 08:57:37.028: E/AndroidRuntime(341): at java.lang.reflect.Method.invoke(Method.java:507)

05-30 08:57:37.028: E/AndroidRuntime(341): at android.view.View$1.onClick(View.java:2139)

05-30 08:57:37.028: E/AndroidRuntime(341): ... 11 more

05-30 08:57:37.028: E/AndroidRuntime(341): Caused by: java.lang.NullPointerException

05-30 08:57:37.028: E/AndroidRuntime(341): at android.app.Activity.findViewById(Activity.java:1647)

05-30 08:57:37.028: E/AndroidRuntime(341): at my.project.CI.NetworkXMLActivity.loadList(NetworkXMLActivity.java:51)

05-30 08:57:37.028: E/AndroidRuntime(341): at my.project.CI.CocktailIndexActivity.reLoadList1(CocktailIndexActivity.java:51)

05-30 08:57:37.028: E/AndroidRuntime(341): ... 14 more