안드로이드 개발 질문/답변
(글 수 45,052)
public class cybs extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new notice(this).getXMLDataList();
setContentView(R.layout.notice);}
php파일을 만들어서 웹서버에 올린후에 해독중에 자꾸 오류가 납니다..
위에 소스가 리스트 뷰가 나오는 클래스구요
package chk.buscard.app;
import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.http.NameValuePair; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList;
import android.app.Activity; import android.util.Log; import android.widget.ListView; import android.widget.Toast;
public class notice {
public Activity act;
public ArrayList<noticeMainItem> noticeMA;
public String TAG = "notice";
public String encoding = "UTF-8";
public notice() {
}
public notice(Activity tmpact){
act = tmpact;
}
public void getXMLDataList(){
String theUrl = "http://www.kkaoul.da.to/notice_list.php";
Log.i(TAG, theUrl);
ArrayList<NameValuePair> httpParams = new ArrayList<NameValuePair>();
/*httpParams.add(new BasicNameValuePair("",));*/
cmsHTTP cmsHttp = new cmsHTTP();
cmsHttp.encoding = encoding;
String tmpData = cmsHttp.sendPost(theUrl, httpParams);
Log.i(TAG, tmpData);
ArrayList<noticeMainItem> noticeMI = new ArrayList<noticeMainItem>();
HashMap<String,String> hm = xml2HashMap(tmpData);
for (int i=0; i<Integer.parseInt(hm.get("count")); i++){
noticeMI.add(new noticeMainItem(hm.get("subject[" + i + "]"), hm.get("reg_date[" + i + "]")));
}
noticeListAdapter noticeListadapter = new noticeListAdapter(act, R.layout.notice_row_main, noticeMI);
ListView noticeListMain = (ListView) act.findViewById(R.id.noticeListMain);
noticeListMain.setAdapter(noticeListadapter);
}
public HashMap<String, String> xml2HashMap (String tmpData){
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();
Log.i(TAG, "dataNodeList.getLength():" +dataNodeList.getLength());
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();
Log.i(TAG, nodeName + "[" + "]" + nodeValue);
hm.put(nodeName + "[" + "]", nodeValue);
}
}//for j
}c++; //for i
hm.put("count", Integer.toString(c));
}catch (Exception e){
Toast.makeText(act, e.getMessage(), 10).show();
Log.e(TAG, e.getMessage());
}
return hm;
}
}
이 소스가 XML해독후에 밑에 소스를 통해서 리스트뷰에 출력하는 소스입니다.
package chk.buscard.app;
import java.util.ArrayList;
import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView;
class noticeMainItem{
String reg_date;
String subject;
noticeMainItem(String reg_date_tmp, String subject_tmp){
reg_date = reg_date_tmp;
subject = subject_tmp;
}
}
public class noticeListAdapter extends BaseAdapter {
LayoutInflater inflater;
ArrayList<noticeMainItem> noticeMA;
Context mContext;
int mListLayout;
public noticeListAdapter(Context tContext, int listLayout,
ArrayList<noticeMainItem> noticeMAT){
mContext = tContext;
mListLayout = listLayout;
noticeMA = noticeMAT;
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
// TODO Auto-generated method stub
return noticeMA.size();
}
public Object getItem(int rowNum) {
// TODO Auto-generated method stub
return noticeMA.get(rowNum);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null){
convertView = inflater.inflate(mListLayout, parent, false);
}
TextView notice_reg_date = (TextView) convertView.findViewById(R.id.notice_reg_date);
notice_reg_date.setText(noticeMA.get(position).reg_date);
TextView notice_subject = (TextView) convertView.findViewById(R.id.notice_subject);
notice_subject.setText(noticeMA.get(position).subject);
return convertView;
}
}
그리고 밑에가 로그캣입니다.
10-09 22:24:34.702: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=chk.buscard.app/.cybs }
10-09 22:24:34.822: DEBUG/AndroidRuntime(267): Shutting down VM
10-09 22:24:34.843: DEBUG/jdwp(267): adbd disconnected
10-09 22:24:34.883: INFO/AndroidRuntime(267): NOTE: attach of thread 'Binder Thread #3' failed
10-09 22:24:34.932: INFO/ActivityManager(59): Start proc chk.buscard.app for activity chk.buscard.app/.cybs: pid=274 uid=10036 gids={3003}
10-09 22:24:35.333: WARN/ActivityThread(274): Application chk.buscard.app is waiting for the debugger on port 8100...
10-09 22:24:35.352: INFO/System.out(274): Sending WAIT chunk
10-09 22:24:35.372: INFO/dalvikvm(274): Debugger is active
10-09 22:24:35.402: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x2fe310:0x2fe41c] in 1114388 ns
10-09 22:24:35.583: INFO/System.out(274): Debugger has connected
10-09 22:24:35.583: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:35.782: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:35.992: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:36.053: INFO/ARMAssembler(59): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x343c80:0x343d3c] in 898998 ns
10-09 22:24:36.192: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:36.393: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:36.593: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:36.794: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:37.002: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:37.202: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:37.402: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:37.641: INFO/System.out(274): waiting for debugger to settle...
10-09 22:24:37.849: INFO/System.out(274): debugger has settled (1322)
10-09 22:24:38.162: INFO/notice(274): http://www.kkaoul.da.to/notice_list.php
10-09 22:24:38.222: VERBOSE/cmsHTTP(274): Content-Type: application/x-www-form-urlencoded
10-09 22:24:39.152: INFO/notice(274): <?xml version="1.0" encoding="UTF-8"?><lists>
10-09 22:24:39.152: INFO/notice(274): <data>
10-09 22:24:39.152: INFO/notice(274): <rowid>2</rowid>
10-09 22:24:39.152: INFO/notice(274): <subject><![CDATA[최초공지 ]]></subject>
10-09 22:24:39.152: INFO/notice(274): <reg_date>10/3</reg_date>
10-09 22:24:39.152: INFO/notice(274): <content><![CDATA[오징어와 꼴뚜기는 바다의왕자. 홍합과 대합은 바다의 공주. 두개를 같이 넣고 해물탕 끓여먹고싶다.]]></content>
10-09 22:24:39.152: INFO/notice(274): </data>
10-09 22:24:39.152: INFO/notice(274): <data>
10-09 22:24:39.152: INFO/notice(274): <rowid>1</rowid>
10-09 22:24:39.152: INFO/notice(274): <subject><![CDATA[두번째공지]]></subject>
10-09 22:24:39.152: INFO/notice(274): <reg_date>10/3</reg_date>
10-09 22:24:39.152: INFO/notice(274): <content><![CDATA[미안합니다. 고작 나란 사람이 돈쓰길 미친듯 좋아합니다. 기다립니다. 로또로 대박나는날 미치도록 그날을 원합니다.]]></content>
10-09 22:24:39.152: INFO/notice(274): </data>
10-09 22:24:39.152: INFO/notice(274): </lists>
10-09 22:24:39.583: INFO/notice(274): dataNodeList.getLength():9
10-09 22:24:39.593: INFO/notice(274): rowid[]2
10-09 22:24:39.593: INFO/notice(274): subject[]최초공지
10-09 22:24:39.602: INFO/notice(274): reg_date[]10/3
10-09 22:24:39.602: INFO/notice(274): content[]오징어와 꼴뚜기는 바다의왕자. 홍합과 대합은 바다의 공주. 두개를 같이 넣고 해물탕 끓여먹고싶다.
10-09 22:24:39.612: INFO/notice(274): dataNodeList.getLength():9
10-09 22:24:39.622: INFO/notice(274): rowid[]1
10-09 22:24:39.622: INFO/notice(274): subject[]두번째공지
10-09 22:24:39.633: INFO/notice(274): reg_date[]10/3
10-09 22:24:39.633: INFO/notice(274): content[]미안합니다. 고작 나란 사람이 돈쓰길 미친듯 좋아합니다. 기다립니다. 로또로 대박나는날 미치도록 그날을 원합니다.
10-09 22:24:44.835: WARN/ActivityManager(59): Launch timeout has expired, giving up wake lock!
10-09 22:24:45.244: WARN/ActivityManager(59): Activity idle timeout for HistoryRecord{43f8bbd8 chk.buscard.app/.cybs}
10-09 22:29:23.182: DEBUG/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
10-09 22:34:23.187: DEBUG/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
고수님들 해석 좀 부탁드릴께여 ㅜㅠ 밤새 이거 가지고 헤맸어요 ㅜㅠ



아무도 코멘트 안해주시네요 ㅠㅜ