Die Methode findViewById(int) ist nicht definiert

Ich bin neu in der Android Entwicklung und ich bin versucht zu code eine kleine app, die ermöglicht es mir, zu schnappen eine externe JSON-Datei und analysieren es. Ich habe diese arbeiten, aber es wird nicht funktionieren, wenn ich versuche, führen Sie es im hintergrund als AsyncTask. Eclipse gibt mir die Fehlermeldung

Die Methode findViewById(int) ist nicht definiert für den Typ LongOperation

in dieser Zeile:

TextView txtView1 = (TextView)findViewById(R. id.TextView01);

Hier ist mein code:

public class Main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        new LongOperation().execute();
    }
}


class LongOperation extends AsyncTask<String, Void, String> {
    private final Context LongOperation = null;


    @Override
    protected String doInBackground(String... params) {
        try {
            URL json = new URL("http://www.corps-marchia.de/jsontest.php");
            URLConnection tc = json.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));

            String line;
            while ((line = in.readLine()) != null) {
                    JSONArray ja = new JSONArray(line);
                    JSONObject jo = (JSONObject) ja.get(0);
                    TextView txtView1 = (TextView)findViewById(R.id.TextView01);
                    txtView1.setText(jo.getString("text") + " - " + jo.getString("secondtest"));
            }
        } catch (MalformedURLException e) {
            Toast.makeText(this.LongOperation, "Malformed URL Exception: " + e, Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            Toast.makeText(this.LongOperation, "IO Exception: " + e, Toast.LENGTH_LONG).show();
        } catch (JSONException e) {
            Toast.makeText(this.LongOperation, "JSON Exception: " + e, Toast.LENGTH_LONG).show();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
    }
    protected void onPreExecute() {
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        ProgressDialog pd = new ProgressDialog(LongOperation);
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setMessage("Working...");
        pd.setIndeterminate(true);
        pd.setCancelable(false);
    }    

}

Irgendwelche Ideen auf, wie man dieses Problem beheben?

InformationsquelleAutor robs | 2011-02-12

Schreibe einen Kommentar