0

I am beginner in android, and for a project for a uny course we have to develop 5 simple apps and then "combine" them in one.So you start each app from a single Activity/ListView. All the apps are running ok individually but when running one app from the listview i get the following *AsyncTask #1 an error occured while executing doinBackground();*

 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    reportarray= new ArrayList<String>();


    try {
        URL url = new URL("http://www.yr.no/sted/Sverige/Kronoberg/V%E4xj%F6/forecast.xml");
        AsyncTask task = new WeatherRetriever().execute(url);
    } catch (IOException ioe ) {
        ioe.printStackTrace();
    }
    adapter= new Adapter(this);
    setListAdapter(adapter);



}

It seems that is a thread issue , here is some more code i use

private class WeatherRetriever extends AsyncTask<URL, Void, WeatherReport> {
    protected WeatherReport doInBackground(URL... urls) {
        try {
            return WeatherHandler.getWeatherReport(urls[0]);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } 
    }

    protected void onProgressUpdate(Void... progress) {

    }

    protected void onPostExecute(WeatherReport result) {
        report = result;




        runOnUiThread(new Runnable() {
              public void run() {



                  reportarray.add(report.toString());;

                  for (WeatherForecast forecast : report) {
                        reportarray.add(forecast.toString());

                    }
                adapter.notifyDataSetChanged();
              }
            });
        PrintReportToConsole();


    }
}

}

LOGCAT OUTPUT

09-10 14:51:36.347: E/AndroidRuntime(1411): FATAL EXCEPTION: AsyncTask #1
09-10 14:51:36.347: E/AndroidRuntime(1411): java.lang.RuntimeException: An error occured while executing doInBackground()
09-10 14:51:36.347: E/AndroidRuntime(1411):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at java.lang.Thread.run(Thread.java:856)
09-10 14:51:36.347: E/AndroidRuntime(1411): Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at com.example.ass1.VaxjoWeather$WeatherRetriever.doInBackground(VaxjoWeather.java:133)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at com.example.ass1.VaxjoWeather$WeatherRetriever.doInBackground(VaxjoWeather.java:1)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
09-10 14:51:36.347: E/AndroidRuntime(1411):     ... 4 more
09-10 14:51:36.347: E/AndroidRuntime(1411): Caused by: java.lang.RuntimeException: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at com.example.ass1.WeatherHandler.getWeatherReport(WeatherHandler.java:54)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at com.example.ass1.VaxjoWeather$WeatherRetriever.doInBackground(VaxjoWeather.java:131)
09-10 14:51:36.347: E/AndroidRuntime(1411):     ... 7 more
09-10 14:51:36.347: E/AndroidRuntime(1411): Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
09-10 14:51:36.347: E/AndroidRuntime(1411):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
2
  • 1
    Add logs in the question Commented Sep 10, 2013 at 14:45
  • 1
    Can you post logcat output here? Commented Sep 10, 2013 at 14:45

1 Answer 1

6

It appears you don't have the appropriate permissions. Add this line to your manifest.xml

 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you codeMagic , i dont have enouph reputation to vote up , sorry:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.