tags:

views:

53

answers:

3

aka, what is wrong with this code:-

package com.mez.appofjaq;

import com.mez.appofjaq.RssParser.RssFeed;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.webkit.WebView;

public class AppOfJaq extends Activity {

    protected static final int REFRESH = 0;

    String streamTitle = "";
    protected ProgressDialog pd;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        pd.show(this, "Loading..", "Loading Feed");
        setContentView(R.layout.main);
        new Thread(new Runnable(){
            public void run() {
                loadFeed();
                pd.dismiss();
            }
        }).start();

    }

    private void loadFeed()
    {
        RssParser rp = new RssParser("http://shotofjaq.org/feed");
        rp.parse();

        RssFeed feed = rp.getFeed();

        if (feed.getItems() != null)
        {
            streamTitle = feed.getItems().get(0).content;
        }
        WebView result = (WebView)findViewById(R.id.result);
        result.loadData(streamTitle, "text/html", "utf-8");
    }

}
A: 

I guess you are missing a parameter.

From my code:

pd = ProgressDialog.show(this, "", getString(R.string.loading_msg), true);
Macarse
A: 

You'll be getting a NPE on pd.show(this, "Loading..", "Loading Feed");

Should be

pd = ProgressDialog.show(this, "Loading..", "Loading Feed");

as Macarse has noted.

alex
A: 

Macarse and alex are both right (and both missing information).

Macarse's code is what you need to use to get it to work. It includes the missing parameter (the true at the end to make it an indeterminate dialog) and it fixes the Null Pointer Exception (NPE) by calling ProgressDialog.show instead of pd.show.

I know this isn't exactly an answer on its own, but I thought it would help someone else to know why both alex and Macarse are correct with their answers.

The end result is that you should have the following code, for the reasons above:

pd = ProgressDialog.show(this, "Loading...", "Loading Feed", true);

or this (if using strings.xml for your strings):

pd = ProgressDialog.show(this, getString(R.string.loading_title),
                         getString(R.string.loading_msg), true); 
kiswa
Damnit, you've made it hard here to accept an answer now ;)
Mez
Hehe, sorry about that. I've made my answer more complete now, maybe it's the most helpful?
kiswa