XML 파일을 구문 분석하려고합니다. 나는 많은 것을 수색했고 마침내 이것을 발견했다. 내 자신의 코드를 작성하지만 지금 문제가 있습니다. 내가 변경 라디오 버튼에 의해 (기능을 시작할 때 : 나는 오류가 당신은 내 실수를 해결하는 데 도움이 할 수 여기에 Android : Xml 구문 분석
내 코드입니다. 여기에public class Download_database extends Activity {
static String URL = "http://ganjoor.sourceforge.net/newgdbs.xml";
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_download_database);
RadioGroup download_section_group=(RadioGroup)findViewById(R.id.download_section_grop);
RadioButton newgdb=(RadioButton)findViewById(R.id.radio_newgdb);
RadioButton sitegdb=(RadioButton)findViewById(R.id.radio_sitegdb);
RadioButton programgdb=(RadioButton)findViewById(R.id.radio_programgdb);
download_section_group.check(R.id.radio_newgdb);
final TextView hint=(TextView)findViewById(R.id.txt_download_db_hint);
TabHost tabs=(TabHost)findViewById(R.id.download_cat_tabhost);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("down_tag1");
spec.setContent(R.id.download_cat_01);
spec.setIndicator(getString(R.string.txt_download_tab_download_sections));
tabs.addTab(spec);
spec=tabs.newTabSpec("down_tag2");
spec.setContent(R.id.download_cat_02);
spec.setIndicator(getString(R.string.txt_download_tab_download_list));
tabs.addTab(spec);
download_section_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
if(R.id.radio_newgdb== arg1){
hint.setText(getString(R.string.txt_download_hint_newgdb));
URL = "http://ganjoor.sourceforge.net/newgdbs.xml";
xmlp(URL);
}
if(R.id.radio_sitegdb== arg1){
hint.setText(getString(R.string.txt_download_hint_sitedb));
URL = "http://ganjoor.sourceforge.net/sitegdbs.xml";
xmlp(URL);
}
if(R.id.radio_programgdb== arg1){
hint.setText(getString(R.string.txt_download_hint_programgdb));
URL = "http://ganjoor.sourceforge.net/programgdbs.xml";
xmlp(URL);
}
}
});
if(isOnline()){
}
else{
Toast.makeText(this, "you are not connected to internet..Please check your connections", 1).show();
}
}
private void xmlp(String url){
Log.i(URL, "call xmlp");
String xml = parser.getXmlFromUrl(url); // getting XML
Log.i("getting DOM element", "getting DOM element");
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(parser.KEY_gdb);
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(parser.KEY_CatName, parser.getValue(e, parser.KEY_CatName));
map.put(parser.KEY_PoetID, parser.getValue(e, parser.KEY_PoetID));
map.put(parser.KEY_DownloadUrl, parser.getValue(e, parser.KEY_DownloadUrl));
map.put(parser.KEY_PubDate, parser.getValue(e, parser.KEY_PubDate));
map.put(parser.KEY_FileSizeInByte,"Size:"+ parser.getValue(e,parser.KEY_FileSizeInByte));
// adding HashList to ArrayList
menuItems.add(map);
ListView list=(ListView)findViewById(R.id.database_list);
ListAdapter adapter = new SimpleAdapter(this, menuItems,R.layout.list_item,new String[] {parser.KEY_CatName,parser.KEY_PoetID, parser.KEY_DownloadUrl ,parser.KEY_PubDate,parser.KEY_FileSizeInByte}, new int[] {
R.id.chk_database_list_item, R.id.txt_database_poet_id, R.id.txt_database_download_link,R.id.txt_database_pub_date,R.id.txt_database_size });
list.setAdapter(adapter);
}
}
및 내 XMLParser
클래스 :
package co.tosca.persianpoem;
import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import android.util.Log;
public class XMLParser {
// XML node keys
public static final String KEY_gdb = "gdb"; // parent node
public static final String KEY_CatName = "CatName";
public static final String KEY_PoetID = "PoetID";
public static final String KEY_DownloadUrl = "DownloadUrl";
public static final String KEY_FileSizeInByte = "FileSizeInByte";
public static final String KEY_PubDate = "PubDate";
public String getXmlFromUrl(String url) {
String xml = null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
return xml;
}
public Document getDomElement(String xml){
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (SAXException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (IOException e) {
Log.e("Error: ", e.getMessage());
return null;
}
// return DOM
return doc;
}
public String getValue(Element item, String str) {
NodeList n = item.getElementsByTagName(str);
return this.getElementValue(n.item(0));
}
public final String getElementValue(Node elem) {
Node child;
if(elem != null){
if (elem.hasChildNodes()){
for(child = elem.getFirstChild(); child != null; child = child.getNextSibling()){
if(child.getNodeType() == Node.TEXT_NODE ){
return child.getNodeValue();
}
}
}
}
return "";
}
}
내가 resive
마지막 오류 : 여기
04-12 21:35:08.822: I/http://ganjoor.sourceforge.net/sitegdbs.xml(2460): call xmlp
04-12 21:35:08.872: D/AndroidRuntime(2460): Shutting down VM
04-12 21:35:08.872: W/dalvikvm(2460): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
04-12 21:35:08.902: E/AndroidRuntime(2460): FATAL EXCEPTION: main
04-12 21:35:08.902: E/AndroidRuntime(2460): android.os.NetworkOnMainThreadException
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1108)
04-12 21:35:08.902: E/AndroidRuntime(2460): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
04-12 21:35:08.902: E/AndroidRuntime(2460): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
04-12 21:35:08.902: E/AndroidRuntime(2460): at java.net.InetAddress.getAllByName(InetAddress.java:220)
04-12 21:35:08.902: E/AndroidRuntime(2460): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
04-12 21:35:08.902: E/AndroidRuntime(2460): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
04-12 21:35:08.902: E/AndroidRuntime(2460): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
04-12 21:35:08.902: E/AndroidRuntime(2460): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
04-12 21:35:08.902: E/AndroidRuntime(2460): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:580)
04-12 21:35:08.902: E/AndroidRuntime(2460): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:512)
04-12 21:35:08.902: E/AndroidRuntime(2460): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:490)
04-12 21:35:08.902: E/AndroidRuntime(2460): at co.tosca.persianpoem.XMLParser.getXmlFromUrl(XMLParser.java:42)
04-12 21:35:08.902: E/AndroidRuntime(2460): at co.tosca.persianpoem.Download_database.xmlp(Download_database.java:123)
04-12 21:35:08.902: E/AndroidRuntime(2460): at co.tosca.persianpoem.Download_database.access$0(Download_database.java:121)
04-12 21:35:08.902: E/AndroidRuntime(2460): at co.tosca.persianpoem.Download_database$1.onCheckedChanged(Download_database.java:94)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.widget.RadioGroup.access$600(RadioGroup.java:52)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:342)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.widget.CompoundButton.setChecked(CompoundButton.java:132)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.widget.CompoundButton.toggle(CompoundButton.java:91)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.widget.RadioButton.toggle(RadioButton.java:81)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.widget.CompoundButton.performClick(CompoundButton.java:103)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.view.View$PerformClick.run(View.java:14263)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.os.Handler.handleCallback(Handler.java:605)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.os.Handler.dispatchMessage(Handler.java:92)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.os.Looper.loop(Looper.java:137)
04-12 21:35:08.902: E/AndroidRuntime(2460): at android.app.ActivityThread.main(ActivityThread.java:4441)
04-12 21:35:08.902: E/AndroidRuntime(2460): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 21:35:08.902: E/AndroidRuntime(2460): at java.lang.reflect.Method.invoke(Method.java:511)
04-12 21:35:08.902: E/AndroidRuntime(2460): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-12 21:35:08.902: E/AndroidRuntime(2460): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-12 21:35:08.902: E/AndroidRuntime(2460): at dalvik.system.NativeStart.main(Native Method)
내 권한이다 :사용하는 동안
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
내가 그 xml 파일 중 하나를 포함 XML로 문자열을 사용하려고 (즉를 찾는 문제가? 인터넷에 연결 또는 XML을 구문 분석에있어)하지만 너무 오류가 발생, 여기 내 로그 캣인가 사전 정의 된 문자열
04-12 21:33:24.032: I/http://ganjoor.sourceforge.net/sitegdbs.xml(1972): call xmlp
04-12 21:33:24.032: I/getting DOM element(1972): getting DOM element
04-12 21:33:24.072: D/AndroidRuntime(1972): Shutting down VM
04-12 21:33:24.072: W/dalvikvm(1972): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
04-12 21:33:24.082: E/AndroidRuntime(1972): FATAL EXCEPTION: main
04-12 21:33:24.082: E/AndroidRuntime(1972): java.lang.NullPointerException
04-12 21:33:24.082: E/AndroidRuntime(1972): at co.tosca.persianpoem.Download_database.xmlp(Download_database.java:190)
04-12 21:33:24.082: E/AndroidRuntime(1972): at co.tosca.persianpoem.Download_database.access$0(Download_database.java:121)
04-12 21:33:24.082: E/AndroidRuntime(1972): at co.tosca.persianpoem.Download_database$1.onCheckedChanged(Download_database.java:94)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.widget.RadioGroup.access$600(RadioGroup.java:52)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:342)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.widget.CompoundButton.setChecked(CompoundButton.java:132)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.widget.CompoundButton.toggle(CompoundButton.java:91)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.widget.RadioButton.toggle(RadioButton.java:81)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.widget.CompoundButton.performClick(CompoundButton.java:103)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.view.View$PerformClick.run(View.java:14263)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.os.Handler.handleCallback(Handler.java:605)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.os.Handler.dispatchMessage(Handler.java:92)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.os.Looper.loop(Looper.java:137)
04-12 21:33:24.082: E/AndroidRuntime(1972): at android.app.ActivityThread.main
(ActivityThread.java:4441)
04-12 21:33:24.082: E/AndroidRuntime(1972): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 21:33:24.082: E/AndroidRuntime(1972): at java.lang.reflect.Method.invoke(Method.java:511)
04-12 21:33:24.082: E/AndroidRuntime(1972): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-12 21:33:24.082: E/AndroidRuntime(1972): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-12 21:33:24.082: E/AndroidRuntime(1972): at dalvik.system.NativeStart.main(Native Method)
편집 XML : me..No 도움이 모든 친구 덕분에 내가 내가 기능을 downloadxml하는 AsyncTask
을 추가하고 난 더 이상 네트워크 오류가 발생 didnot 내 문제 중 하나가 고정 된 생각합니다. . 여기 내 새로운 다운로드 XML 함수입니다
public class getxml extends AsyncTask<String, Void,String>{
@Override
protected String doInBackground(String... url) {
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url[0]);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
// e.printStackTrace();
} catch (ClientProtocolException e) {
// e.printStackTrace();
} catch (IOException e) {
// e.printStackTrace();
}
Log.i("getxml", xml);
return xml;
}
}
하지만 지금은 NullPointerException
입니다.하지만 왜 그런지 알 수 없습니다. 왜 그 이유를 찾아야합니까?
편집 : nullexeption 오류를 수정하기 위해 많은 노력을했지만 그 이유는 찾을 수 없습니다. 되지 않은 problem..I이 문제는 내 목록에 생각
private void xmlp(String url){
Log.i(URL, "call xmlp");
//String xml = parser.getXmlFromUrl(url); // getting XML old way
new getxml().execute(url);// getting XML new way
Log.i("xml Content", xml);
try{
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(parser.KEY_gdb);
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(parser.KEY_CatName, parser.getValue(e, parser.KEY_CatName));
map.put(parser.KEY_PoetID, parser.getValue(e, parser.KEY_PoetID));
map.put(parser.KEY_DownloadUrl, parser.getValue(e, parser.KEY_DownloadUrl));
map.put(parser.KEY_PubDate, parser.getValue(e, parser.KEY_PubDate));
map.put(parser.KEY_FileSizeInByte,"Size:"+ parser.getValue(e,parser.KEY_FileSizeInByte));
// adding HashList to ArrayList
menuItems.add(map);
}
Log.i("menuItems", menuItems.toString());
ListView list=(ListView)findViewById(R.id.database_list);
ListAdapter adapter = new SimpleAdapter(this, menuItems,R.layout.database_list_item,new String[] {parser.KEY_CatName}, new int[] {
R.id.chk_database_list_item });
list.setAdapter(adapter);
}
catch (NullPointerException ex){
Log.i("NullPointerException", ex.getMessage());
}
}
당신은 내가 메뉴 아이템을 기록 보는 바와 같이 나는이 오류
04-13 12:21:50.372: I/menuItems(3295): [{DownloadUrl=http://sourceforge.net/projects/ganjoor/files/gdb/abvsEid-abvalkhir.zip, PubDate=2011-09-24, FileSizeInByte=Size:123331, CatName=ابوسعيد ابوالخير, PoetID=26}, {DownloadUrl=http://sourceforge.net/projects/ganjoor/files/gdb/asdi-tvsi.zip, PubDate=2012-05-05, FileSizeInByte=Size:559711, CatName=اسدي توسي, PoetID=52}, {DownloadUrl=http://sourceforge.net/projects/ganjoor/files/gdb/aghbal-lahvri.zip, PubDate=2011-09-24, FileSizeInByte=Size:551922, CatName=اقبال لاهوري, PoetID=42}, {DownloadUrl=http://sourceforge.net/projects/ganjoor/files/gdb/amirkhsrv-dhlvi.zip, PubDate=2011-09-24, FileSizeInByte=Size:505209, CatName=اميرخسرو دهلوي, PoetID=34}, {DownloadUrl=http://sourceforge.net/projects/ganjoor/files/gdb/anvri.zip, PubDate=2011-09-24, FileSizeInByte=Size:902760, CatName=انوري, PoetID=18}, {DownloadUrl=http://sourceforge.net/projects/ganjoor/files/gdb/avhdi.zip, PubDate=2011-09-24, FileSizeInByte=Size:991556, CatName=اوحدي, PoetID=19}, {DownloadUrl=http://sourceforge.net/projects/ganjoor/files/gdb/babatahr.zip, PubDate=2011-09-24, FileSizeInByte=Size:60641, CatName=باباطاهر, PoetID=28}, {DownloadUrl=http://sourceforge.net/projects/ganjoor/files/gdb/bidl-dhlvi.zip, PubDate=2011-09-24, FileSizeInByte=Size:2406463, CatName=بيدل دهلوي, PoetID=43}]
04-13 12:13:06.912: D/AndroidRuntime(3149): Shutting down VM
04-13 12:13:06.912: W/dalvikvm(3149): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
04-13 12:13:06.912: E/AndroidRuntime(3149): FATAL EXCEPTION: main
04-13 12:13:06.912: E/AndroidRuntime(3149): java.lang.NullPointerException
04-13 12:13:06.912: E/AndroidRuntime(3149): at co.tosca.persianpoem.Download_database.xmlp(Download_database.java:258)
04-13 12:13:06.912: E/AndroidRuntime(3149): at co.tosca.persianpoem.Download_database.access$0(Download_database.java:132)
04-13 12:13:06.912: E/AndroidRuntime(3149): at co.tosca.persianpoem.Download_database$1.onCheckedChanged(Download_database.java:104)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.widget.RadioGroup.access$600(RadioGroup.java:52)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:342)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.widget.CompoundButton.setChecked(CompoundButton.java:132)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.widget.CompoundButton.toggle(CompoundButton.java:91)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.widget.RadioButton.toggle(RadioButton.java:81)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.widget.CompoundButton.performClick(CompoundButton.java:103)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.view.View$PerformClick.run(View.java:14263)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.os.Handler.handleCallback(Handler.java:605)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.os.Handler.dispatchMessage(Handler.java:92)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.os.Looper.loop(Looper.java:137)
04-13 12:13:06.912: E/AndroidRuntime(3149): at android.app.ActivityThread.main(ActivityThread.java:4441)
04-13 12:13:06.912: E/AndroidRuntime(3149): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 12:13:06.912: E/AndroidRuntime(3149): at java.lang.reflect.Method.invoke(Method.java:511)
04-13 12:13:06.912: E/AndroidRuntime(3149): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-13 12:13:06.912: E/AndroidRuntime(3149): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-13 12:13:06.912: E/AndroidRuntime(3149): at dalvik.system.NativeStart.main(Native Method)
을 가지고 그리고 그것은이 XML에서 읽기 솔기 : 여기 내 코드입니다 어댑터 :(나는 오류가 내 사용자 지정 목록 레이아웃을 확인하지만 난 여기
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/chk_database_list_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="CheckBox" />
<TextView
android:id="@+id/txt_database_size"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical|end"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/txt_database_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/txt_database_pub_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="TextView" />
<TextView
android:id="@+id/txt_database_download_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/txt_database_poet_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
내 customlayout을 게시, 그래서 아무것도 찾을 수 없습니다
list.setAdapter(adapter);
을 포함 258가 얻을 라인 나는이 새로운 오류가 발생했습니다
catch (NullPointerException ex){
Log.i("NullPointerException", ex.getMessage());
}
내 기능이 라인을 추가 할 때 414,기계류 것입니다
04-13 12:21:50.372: W/dalvikvm(3295): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
04-13 12:21:50.382: E/AndroidRuntime(3295): FATAL EXCEPTION: main
04-13 12:21:50.382: E/AndroidRuntime(3295): java.lang.NullPointerException: println needs a message
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.util.Log.println_native(Native Method)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.util.Log.i(Log.java:159)
04-13 12:21:50.382: E/AndroidRuntime(3295): at co.tosca.persianpoem.Download_database.xmlp(Download_database.java:263)
04-13 12:21:50.382: E/AndroidRuntime(3295): at co.tosca.persianpoem.Download_database.access$0(Download_database.java:132)
04-13 12:21:50.382: E/AndroidRuntime(3295): at co.tosca.persianpoem.Download_database$1.onCheckedChanged(Download_database.java:112)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.widget.RadioGroup.access$600(RadioGroup.java:52)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:342)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.widget.CompoundButton.setChecked(CompoundButton.java:132)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.widget.CompoundButton.toggle(CompoundButton.java:91)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.widget.RadioButton.toggle(RadioButton.java:81)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.widget.CompoundButton.performClick(CompoundButton.java:103)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.view.View$PerformClick.run(View.java:14263)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.os.Handler.handleCallback(Handler.java:605)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.os.Handler.dispatchMessage(Handler.java:92)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.os.Looper.loop(Looper.java:137)
04-13 12:21:50.382: E/AndroidRuntime(3295): at android.app.ActivityThread.main(ActivityThread.java:4441)
04-13 12:21:50.382: E/AndroidRuntime(3295): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 12:21:50.382: E/AndroidRuntime(3295): at java.lang.reflect.Method.invoke(Method.java:511)
04-13 12:21:50.382: E/AndroidRuntime(3295): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-13 12:21:50.382: E/AndroidRuntime(3295): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-13 12:21:50.382: E/AndroidRuntime(3295): at dalvik.system.NativeStart.main(Native Method)
라인 (263)이 포함
이Log.i("NullPointerException", ex.getMessage());
여러 번 물어 왔습니다. 이 [중복 스레드] (http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception)를 살펴보십시오. –
실제로 문제는 XML 파서를 선택하는 것이 아닙니다 ... 아직. 이 시점에서 여전히 'AsyncTask'문제입니다. –
P. @ 마지드 SAX 대신 DOM 파서를 사용하여 올바른 선택을했다고 생각합니다. 보통 대용량 또는 복잡한 XML 데이터, 속도 요구 사항, 많은 양의 데이터에 대한 메모리 사용 또는 XML을 사용하기 때문에 필요한 경우에는 SAX로 전환하고 DOM을 구현하는 것이 더 쉽다고 생각합니다. InputStream에서 파싱 될 때 즉석에서 결과를 처리 할 필요가있다. –