views:

145

answers:

1

Sorry that I'm asking such a question, but I'm tryin to make this one run for hours, and I'm not finding the mistake...

public class Main extends ListActivity {
/** Called when the activity is first created. */

ProgressDialog dialog;

@Override
public synchronized void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);     
    new WebLoader().doInBackground("http://sample.sample.com/sample.xml");
}

public class WebLoader extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... params) {
        String result = "";

        try{
            URL url = new URL(params[0]);
            URLConnection conn = url.openConnection();
            InputStream is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            ByteArrayBuffer baf = new ByteArrayBuffer(2048);

            int current = 0;
            while((current = bis.read()) != -1)
            {
                baf.append((byte)current);
            }

            result = new String(baf.toByteArray());
        }

        catch(Exception e)
        {
            Log.e("gullinews", e.getMessage());
        }


        return result;
    }

    @Override
    protected void onPostExecute(String result) {
        dialog.dismiss();
    }

    @Override
    protected void onPreExecute() {
        dialog = ProgressDialog.show(getApplicationContext(), "", 
                "Loading. Please wait...", true);
    }     
  }

}

Running with a debugger shows, that the xml data is downloaded, but there's just black screen. When I tried "setContenView(R.layout.main);" with main.xml:

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

//Edit: okay, I solved one error, didn't solve the rest. Source updated.

My Main problem now is, that I ain't got an Idea why the ProgressDialog doesnt show up. rest should be black, that's right.

A: 

new WebLoader().doInBackground("http://sample.sample.com/sample.xml");

That's not how you use an asynctask. Did you read any documentaton at all?

Falmarri