0

Actually i do XML parsing from my localhost can anyone help to fix my issue. Thanks in advance.

Here my xml tag.

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
   <book id="bk103">
      <author>Corets, Eva</author>
      <title>Maeve Ascendant</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-11-17</publish_date>
      <description>After the collapse of a nanotechnology 
      society in England, the young survivors lay the 
      foundation for a new society.</description>
   </book>
   <book id="bk104">
      <author>Corets, Eva</author>
      <title>Oberon's Legacy</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-03-10</publish_date>
      <description>In post-apocalypse England, the mysterious 
      agent known only as Oberon helps to create a new life 
      for the inhabitants of London. Sequel to Maeve 
      Ascendant.</description>
   </book>
   <book id="bk105">
      <author>Corets, Eva</author>
      <title>The Sundered Grail</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-09-10</publish_date>
      <description>The two daughters of Maeve, half-sisters, 
      battle one another for control of England. Sequel to 
      Oberon's Legacy.</description>
   </book>
   <book id="bk106">
      <author>Randall, Cynthia</author>
      <title>Lover Birds</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-09-02</publish_date>
      <description>When Carla meets Paul at an ornithology 
      conference, tempers fly as feathers get ruffled.</description>
   </book>
   <book id="bk107">
      <author>Thurman, Paula</author>
      <title>Splish Splash</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>A deep sea diver finds true love twenty 
      thousand leagues beneath the sea.</description>
   </book>
   <book id="bk108">
      <author>Knorr, Stefan</author>
      <title>Creepy Crawlies</title>
      <genre>Horror</genre>
      <price>4.95</price>
      <publish_date>2000-12-06</publish_date>
      <description>An anthology of horror stories about roaches,
      centipedes, scorpions  and other insects.</description>
   </book>
   <book id="bk109">
      <author>Kress, Peter</author>
      <title>Paradox Lost</title>
      <genre>Science Fiction</genre>
      <price>6.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>After an inadvertant trip through a Heisenberg
      Uncertainty Device, James Salway discovers the problems 
      of being quantum.</description>
   </book>
   <book id="bk110">
      <author>O'Brien, Tim</author>
      <title>Microsoft .NET: The Programming Bible</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-09</publish_date>
      <description>Microsoft's .NET initiative is explored in 
      detail in this deep programmer's reference.</description>
   </book>
   <book id="bk111">
      <author>O'Brien, Tim</author>
      <title>MSXML3: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-01</publish_date>
      <description>The Microsoft MSXML3 parser is covered in 
      detail, with attention to XML DOM interfaces, XSLT processing, 
      SAX and more.</description>
   </book>
   <book id="bk112">
      <author>Galos, Mike</author>
      <title>Visual Studio 7: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>49.95</price>
      <publish_date>2001-04-16</publish_date>
      <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
   </book>
</catalog>

Here is my Mainactivity.class

public class MainActivity extends ListActivity {

    static final String url="http://10.0.2.2/Book_Detail.xml";
    static final String key_catalog="catalog";
    static final String key_root="book";
    static final String key_id="id";
    static final String key_author="author";
    static final String key_title="title";
    static final String key_genre="genre";
    static final String key_price="price";
    static final String key_date="publish_date";
    static final String key_des="description";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ArrayList< HashMap<String, String>> menuitems=new ArrayList<HashMap<String,String>>();
        XMLParser parser = new XMLParser(); 
        String xml = parser.getXmlFromUrl(url);

        Document doc = parser.getDomElement(xml); // getting DOM element

        //NodeList nl = doc.getElementsByTagName(key_catalog);
        NodeList nl = doc.getElementsByTagName(key_id);
        // 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(key_id, parser.getValue(e, key_id));
        map.put(key_author, "Author:-" + parser.getValue(e, key_author));
        map.put(key_title, "TIitle:-" + parser.getValue(e, key_title)); 
        map.put(key_genre,"Genere" + parser.getValue(e, key_genre));
        map.put(key_price, "Price:"+ parser.getValue(e, key_price));
        map.put(key_date,"Publish_Date "+ parser.getValue(e, key_date));
        map.put(key_des, "Publish_Description"+ parser.getValue(e, key_des));


        menuitems.add(map);
        ListAdapter adapter = new SimpleAdapter(this,menuitems, 
                R.layout.listlay, 
                new String[] { key_author, key_title,key_genre,key_price,key_date,key_des }, new int[] 
                { 
                R.id.authortext, R.id.titletext, R.id.genre,R.id.price,R.id.date,R.id.destext });

                setListAdapter(adapter);

                // selecting single ListView item 
                ListView lv = getListView();

                lv.setOnItemClickListener(new OnItemClickListener() {

                @Override 
                public void onItemClick(AdapterView<?> parent, View view, 
                int position, long id) { 
                // getting values from selected ListItem 
                String author = ((TextView) view.findViewById(R.id.authortext)).getText().toString(); 
                String title = ((TextView) view.findViewById(R.id.titletext)).getText().toString();
                String genre = ((TextView) view.findViewById(R.id.genre)).getText().toString();
                String price = ((TextView) view.findViewById(R.id.price)).getText().toString();
                String date = ((TextView) view.findViewById(R.id.date)).getText().toString();
                String description = ((TextView) view.findViewById(R.id.destext)).getText().toString();

                // Starting new intent 
                Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class); 
                in.putExtra(key_author, author); 
                in.putExtra(key_title, title);
                in.putExtra(key_genre, genre);
                in.putExtra(key_price, price);
                in.putExtra(key_date, date);
                in.putExtra(key_des, description); 
                startActivity(in);

                } 
                }); 
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

My parsing activity..

public class XMLParser {

    public String getXmlFromUrl(String url) {
        // TODO Auto-generated method stub
        return null;
    }

    public Document getDomElement(String xml) {
        // TODO Auto-generated method stub
        return null;
    }

    public String getValue(Element e, String key_Id) {
        // TODO Auto-generated method stub
        return null;
    }

}

My main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >
    </ListView>

</RelativeLayout>

Listact.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 
<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical">

<!-- author -->
<TextView 
android:id="@+id/authortext" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textColor="#FFFF00" 
android:textSize="16sp" 
android:textStyle="bold" 
android:paddingTop="6dip" 
android:paddingBottom="2dip" />

<!-- title Label -->
<TextView 
android:id="@+id/titletext" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textColor="#FFFF00" 
android:textSize="16sp" 

android:paddingBottom="4dip" />

<!--genre Label -->
<TextView 
android:id="@+id/genre" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textColor="#FFFF00" 
android:textSize="16sp"  
android:paddingBottom="6dip" />

<!-- price Label -->
<TextView 
android:id="@+id/price" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textColor="#FFFF00" 
android:textSize="16sp"  
android:paddingBottom="8dip" />

<!-- date Label -->
<TextView 
android:id="@+id/date" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textColor="#FFFF00" 
android:textSize="16sp"  
android:paddingBottom="10dip" />

<!-- description Label -->
<TextView 
android:id="@+id/destext" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textColor="#FFFF00" 
android:textSize="16sp"  
android:paddingBottom="12dip" />




</LinearLayout>

</LinearLayout>

and finally my logcat detail

08-01 12:58:15.813: D/AndroidRuntime(305): Shutting down VM
08-01 12:58:15.813: W/dalvikvm(305): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-01 12:58:15.833: E/AndroidRuntime(305): FATAL EXCEPTION: main
08-01 12:58:15.833: E/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.praveenxml/com.example.praveenxml.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.os.Looper.loop(Looper.java:123)
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 12:58:15.833: E/AndroidRuntime(305):  at java.lang.reflect.Method.invokeNative(Native Method)
08-01 12:58:15.833: E/AndroidRuntime(305):  at java.lang.reflect.Method.invoke(Method.java:521)
08-01 12:58:15.833: E/AndroidRuntime(305):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 12:58:15.833: E/AndroidRuntime(305):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 12:58:15.833: E/AndroidRuntime(305):  at dalvik.system.NativeStart.main(Native Method)
08-01 12:58:15.833: E/AndroidRuntime(305): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.app.ListActivity.onContentChanged(ListActivity.java:245)
08-01 12:58:15.833: E/AndroidRuntime(305):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.app.Activity.setContentView(Activity.java:1647)
08-01 12:58:15.833: E/AndroidRuntime(305):  at com.example.praveenxml.MainActivity.onCreate(MainActivity.java:41)
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 12:58:15.833: E/AndroidRuntime(305):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-01 12:58:15.833: E/AndroidRuntime(305):  ... 11 more
08-01 13:00:06.844: D/AndroidRuntime(333): Shutting down VM
08-01 13:00:06.844: W/dalvikvm(333): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-01 13:00:06.864: E/AndroidRuntime(333): FATAL EXCEPTION: main
08-01 13:00:06.864: E/AndroidRuntime(333): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.praveenxml/com.example.praveenxml.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.os.Looper.loop(Looper.java:123)
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 13:00:06.864: E/AndroidRuntime(333):  at java.lang.reflect.Method.invokeNative(Native Method)
08-01 13:00:06.864: E/AndroidRuntime(333):  at java.lang.reflect.Method.invoke(Method.java:521)
08-01 13:00:06.864: E/AndroidRuntime(333):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 13:00:06.864: E/AndroidRuntime(333):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 13:00:06.864: E/AndroidRuntime(333):  at dalvik.system.NativeStart.main(Native Method)
08-01 13:00:06.864: E/AndroidRuntime(333): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.app.ListActivity.onContentChanged(ListActivity.java:245)
08-01 13:00:06.864: E/AndroidRuntime(333):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.app.Activity.setContentView(Activity.java:1647)
08-01 13:00:06.864: E/AndroidRuntime(333):  at com.example.praveenxml.MainActivity.onCreate(MainActivity.java:41)
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 13:00:06.864: E/AndroidRuntime(333):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-01 13:00:06.864: E/AndroidRuntime(333):  ... 11 more
08-01 13:05:00.735: I/Process(333): Sending signal. PID: 333 SIG: 9
08-01 13:09:38.103: D/AndroidRuntime(389): Shutting down VM
08-01 13:09:38.103: W/dalvikvm(389): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-01 13:09:38.124: E/AndroidRuntime(389): FATAL EXCEPTION: main
08-01 13:09:38.124: E/AndroidRuntime(389): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.praveenxml/com.example.praveenxml.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.os.Looper.loop(Looper.java:123)
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 13:09:38.124: E/AndroidRuntime(389):  at java.lang.reflect.Method.invokeNative(Native Method)
08-01 13:09:38.124: E/AndroidRuntime(389):  at java.lang.reflect.Method.invoke(Method.java:521)
08-01 13:09:38.124: E/AndroidRuntime(389):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 13:09:38.124: E/AndroidRuntime(389):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 13:09:38.124: E/AndroidRuntime(389):  at dalvik.system.NativeStart.main(Native Method)
08-01 13:09:38.124: E/AndroidRuntime(389): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.app.ListActivity.onContentChanged(ListActivity.java:245)
08-01 13:09:38.124: E/AndroidRuntime(389):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.app.Activity.setContentView(Activity.java:1647)
08-01 13:09:38.124: E/AndroidRuntime(389):  at com.example.praveenxml.MainActivity.onCreate(MainActivity.java:41)
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 13:09:38.124: E/AndroidRuntime(389):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-01 13:09:38.124: E/AndroidRuntime(389):  ... 11 more
08-01 13:15:20.284: D/AndroidRuntime(416): Shutting down VM
08-01 13:15:20.284: W/dalvikvm(416): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-01 13:15:20.304: E/AndroidRuntime(416): FATAL EXCEPTION: main
08-01 13:15:20.304: E/AndroidRuntime(416): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.praveenxml/com.example.praveenxml.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.os.Looper.loop(Looper.java:123)
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 13:15:20.304: E/AndroidRuntime(416):  at java.lang.reflect.Method.invokeNative(Native Method)
08-01 13:15:20.304: E/AndroidRuntime(416):  at java.lang.reflect.Method.invoke(Method.java:521)
08-01 13:15:20.304: E/AndroidRuntime(416):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 13:15:20.304: E/AndroidRuntime(416):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 13:15:20.304: E/AndroidRuntime(416):  at dalvik.system.NativeStart.main(Native Method)
08-01 13:15:20.304: E/AndroidRuntime(416): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.app.ListActivity.onContentChanged(ListActivity.java:245)
08-01 13:15:20.304: E/AndroidRuntime(416):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.app.Activity.setContentView(Activity.java:1647)
08-01 13:15:20.304: E/AndroidRuntime(416):  at com.example.praveenxml.MainActivity.onCreate(MainActivity.java:42)
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 13:15:20.304: E/AndroidRuntime(416):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-01 13:15:20.304: E/AndroidRuntime(416):  ... 11 more
08-01 13:17:33.824: D/AndroidRuntime(444): Shutting down VM
08-01 13:17:33.824: W/dalvikvm(444): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-01 13:17:33.834: E/AndroidRuntime(444): FATAL EXCEPTION: main
08-01 13:17:33.834: E/AndroidRuntime(444): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.praveenxml/com.example.praveenxml.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.os.Looper.loop(Looper.java:123)
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 13:17:33.834: E/AndroidRuntime(444):  at java.lang.reflect.Method.invokeNative(Native Method)
08-01 13:17:33.834: E/AndroidRuntime(444):  at java.lang.reflect.Method.invoke(Method.java:521)
08-01 13:17:33.834: E/AndroidRuntime(444):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 13:17:33.834: E/AndroidRuntime(444):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 13:17:33.834: E/AndroidRuntime(444):  at dalvik.system.NativeStart.main(Native Method)
08-01 13:17:33.834: E/AndroidRuntime(444): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.app.ListActivity.onContentChanged(ListActivity.java:245)
08-01 13:17:33.834: E/AndroidRuntime(444):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.app.Activity.setContentView(Activity.java:1647)
08-01 13:17:33.834: E/AndroidRuntime(444):  at com.example.praveenxml.MainActivity.onCreate(MainActivity.java:42)
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 13:17:33.834: E/AndroidRuntime(444):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-01 13:17:33.834: E/AndroidRuntime(444):  ... 11 more

new logcat information...

08-01 14:47:32.854: D/AndroidRuntime(522): Shutting down VM
08-01 14:47:32.854: W/dalvikvm(522): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-01 14:47:32.875: E/AndroidRuntime(522): FATAL EXCEPTION: main
08-01 14:47:32.875: E/AndroidRuntime(522): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.praveenxml/com.example.praveenxml.MainActivity}: java.lang.NullPointerException
08-01 14:47:32.875: E/AndroidRuntime(522):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-01 14:47:32.875: E/AndroidRuntime(522):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-01 14:47:32.875: E/AndroidRuntime(522):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-01 14:47:32.875: E/AndroidRuntime(522):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-01 14:47:32.875: E/AndroidRuntime(522):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 14:47:32.875: E/AndroidRuntime(522):  at android.os.Looper.loop(Looper.java:123)
08-01 14:47:32.875: E/AndroidRuntime(522):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 14:47:32.875: E/AndroidRuntime(522):  at java.lang.reflect.Method.invokeNative(Native Method)
08-01 14:47:32.875: E/AndroidRuntime(522):  at java.lang.reflect.Method.invoke(Method.java:521)
08-01 14:47:32.875: E/AndroidRuntime(522):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 14:47:32.875: E/AndroidRuntime(522):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 14:47:32.875: E/AndroidRuntime(522):  at dalvik.system.NativeStart.main(Native Method)
08-01 14:47:32.875: E/AndroidRuntime(522): Caused by: java.lang.NullPointerException
08-01 14:47:32.875: E/AndroidRuntime(522):  at com.example.praveenxml.MainActivity.onCreate(MainActivity.java:51)
08-01 14:47:32.875: E/AndroidRuntime(522):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 14:47:32.875: E/AndroidRuntime(522):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-01 14:47:32.875: E/AndroidRuntime(522):  ... 11 more
08-01 14:48:58.234: I/Process(522): Sending signal. PID: 522 SIG: 9
4

1 回答 1

0

在您的 Main xml 中,将 ListView 更改为

      <ListView
    android:id="@android:id/list"   <-- this is the mistake You made
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >
      </ListView>

如果您使用的是 ListActivity,则不需要为 ListView 提供 id,而是使用我写的

编辑

对于您的第二个错误:

您会收到此行的 NullPointerException:

    NodeList nl = doc.getElementsByTagName(key_id);   <---here is the NullPointer

这意味着,节点列表试图获取带有标记名“id”的元素,但找不到这个。所以你应该检查这个标签是否真的存在。您的 xml 开头为:

    <book id="bk101">

但也许它应该是这样的,以获取标签 ID:

    <book>
     <id>bk101</id>

尝试从 key_author 获取 NodeList,也许这可行(仅用于测试)。

另一个原因可能是您的 xml 中的 url 有问题。

于 2013-08-01T08:37:15.847 回答