Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • NetworkOnMainThread Exception

    • 1
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 651
    Answer it

    I am trying to call getBitmapFromURL() methos from onCreate() of my Activity and getting NetworkOnMainThread Exception.


    Please help me to solve this problem.


    public static Bitmap getBitmapFromURL(String src) {
            try {
                URL url = new URL(src);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setDoInput(true);
                connection.connect();
                InputStream input = connection.getInputStream();
                Bitmap myBitmap = BitmapFactory.decodeStream(input);
                return myBitmap;
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }    

 1 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: