Get link from an xml file
<p>i have this xml file and i want to get the href string.</p>

<pre><code>&lt;asx version = "3.0"&gt;
    &lt;Title&gt;TITLE&lt;/Title&gt;
    &lt;Author&gt;http://www.domain.com&lt;/Author&gt;
    &lt;Copyright&gt;Copyright&lt;/Copyright&gt;
    &lt;PARAM name="HTMLView" value="http://www.domain.com" /&gt;
    &lt;MoreInfo href="http://www.domain.com" /&gt;
    &lt;entry&gt;
        &lt;ref href="http://145.765.343.09:8180" /&gt;
        &lt;Title&gt;Tile&lt;/Title&gt; 
        &lt;Author&gt;http://www.domain.com&lt;/Author&gt;
    &lt;/entry&gt;
&lt;/asx&gt;
</code></pre>

<p>I have created an adapter but i m getting Nullpointer...what am i doing wrong here please??</p>

<p>this is the code:</p>

<p>basefeedparser.class</p>

<pre><code>public class BaseFeedParser {

    static String feedUrlString = "http://www.domain.com/listen.asx";

    // names of the XML tags
    static final String ASX = "asx";  
    static final String ENTRY = "entry";
    static final String REF = "ref";


    private final URL feedUrl;    

    protected BaseFeedParser(){
        try {
            this.feedUrl = new URL(feedUrlString);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }         
    }

    protected InputStream getInputStream() {
        try {
            return feedUrl.openConnection().getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public List&lt;Message&gt; parse() {
        final Message currentMessage = new Message();
        RootElement root = new RootElement(ASX);
        final List&lt;Message&gt; messages = new ArrayList&lt;Message&gt;();
        Element itemlist = root.getChild(ENTRY);        
        //Element item = itemlist.getChild(ENTRY);
        itemlist.setEndElementListener(new EndElementListener(){
            public void end() {
                messages.add(currentMessage.copy());
            }
        });
        itemlist.getChild(REF).setEndTextElementListener(new EndTextElementListener(){
            public void end(String body) {
                currentMessage.setEntry(body);
            }
        });

        try {
            Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return messages;
    }
}
</code></pre>

<p>message.class</p>

<p>public class Message implements Comparable{</p>

<pre><code>private String entry;
private String Link;


public String getEntry() {
    return entry;
}

public void setEntry(String entry) {
    String imgg  = entry.substring(entry.indexOf("&lt;ref href="));
    String cleanUp = imgg.substring(0, imgg.indexOf("&gt;")+1);//deixnei apo pou ksekina to keimeno
    imgg = imgg.substring(imgg.indexOf("href=") + 5);
    int indexOf = imgg.indexOf("\"");
    if (indexOf==-1){
        indexOf = imgg.indexOf("\"");
    }
    imgg = imgg.substring(0, indexOf);

    setLink(imgg);

    this.entry = this.entry.replace(cleanUp, "");   }



public void setLink(String Link) {
    this.Link = Link;
}
/**
 * @return the Link
 */
public String getLink() {
    return Link;
}



public Message copy(){
    Message copy = new Message();
    copy.entry = entry;
    copy.Link=Link;
    return copy;
}

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Entry: ");
    sb.append(entry);
    sb.append('\n');
    sb.append("Link: ");
    sb.append(Link);
    return sb.toString();
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result
            + ((entry == null) ? 0 : entry.hashCode());
    result = prime * result
    + ((Link == null) ? 0 : Link.hashCode());

    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    Message other = (Message) obj;
    if (entry == null) {
        if (other.entry != null)
            return false;
    } else if (!entry.equals(other.entry))
        return false;
    if (Link == null) {
        if (other.Link != null)
            return false;
    } else if (!Link.equals(other.Link))
        return false;
    return true;
}

public int compareTo(Message another) {
    if (another == null) return 1;
    // sort descending, most recent first
    return 0;
}
</code></pre>

<p>}
 and then i m printing in my main class the link for the ref tag:</p>

<pre><code> for (Message msg : messages){

            au.add(msg.getLink());
            String print=au.toString();
            Toast.makeText(main.this, print, Toast.LENGTH_LONG).show();

}
</code></pre>

<p>LOGCAT:</p>

<pre><code>03-12 09:01:27.164: E/AndroidRuntime(7231): FATAL EXCEPTION: main
03-12 09:01:27.164: E/AndroidRuntime(7231): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.main}: java.lang.NullPointerException
03-12 09:01:27.164: E/AndroidRuntime(7231):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at android.os.Looper.loop(Looper.java:137)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at android.app.ActivityThread.main(ActivityThread.java:4424)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at java.lang.reflect.Method.invokeNative(Native Method)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at java.lang.reflect.Method.invoke(Method.java:511)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at dalvik.system.NativeStart.main(Native Method)
03-12 09:01:27.164: E/AndroidRuntime(7231): Caused by: java.lang.NullPointerException
03-12 09:01:27.164: E/AndroidRuntime(7231):     at com.example.app.main.onCreate(main.java:24)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at android.app.Activity.performCreate(Activity.java:4465)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-12 09:01:27.164: E/AndroidRuntime(7231):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-12 09:01:27.164: E/AndroidRuntime(7231):     ... 11 more
</code></pre>

<p>line 24 is:</p>

<pre><code>for (Message msg : messages)
</code></pre>
