-1

I read on a couple of other posts that when I receive one of these errors that the runtime package(s) are different from the compiling package(s). After looking at the logcat for a long time I can't seem to figure out which package and where to change it.

    05-30 14:57:50.950: E/AndroidRuntime(823): FATAL EXCEPTION: main
05-30 14:57:50.950: E/AndroidRuntime(823): Process: com.example.bitmapdisplay, PID: 823
05-30 14:57:50.950: E/AndroidRuntime(823): java.lang.VerifyError: com/example/bitmapdisplay/MainActivity$displayImages
05-30 14:57:50.950: E/AndroidRuntime(823):  at com.example.bitmapdisplay.MainActivity.onCreate(MainActivity.java:38)
05-30 14:57:50.950: E/AndroidRuntime(823):  at android.app.Activity.performCreate(Activity.java:5231)
05-30 14:57:50.950: E/AndroidRuntime(823):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-30 14:57:50.950: E/AndroidRuntime(823):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-30 14:57:50.950: E/AndroidRuntime(823):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-30 14:57:50.950: E/AndroidRuntime(823):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-30 14:57:50.950: E/AndroidRuntime(823):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-30 14:57:50.950: E/AndroidRuntime(823):  at android.os.Handler.dispatchMessage(Handler.java:102)
05-30 14:57:50.950: E/AndroidRuntime(823):  at android.os.Looper.loop(Looper.java:136)
05-30 14:57:50.950: E/AndroidRuntime(823):  at android.app.ActivityThread.main(ActivityThread.java:5017)
05-30 14:57:50.950: E/AndroidRuntime(823):  at java.lang.reflect.Method.invokeNative(Native Method)
05-30 14:57:50.950: E/AndroidRuntime(823):  at java.lang.reflect.Method.invoke(Method.java:515)
05-30 14:57:50.950: E/AndroidRuntime(823):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-30 14:57:50.950: E/AndroidRuntime(823):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-30 14:57:50.950: E/AndroidRuntime(823):  at dalvik.system.NativeStart.main(Native Method)

Here is my Java code. I have a feeling it's in the AsyncTask class where it messes up:

package com.example.bitmapdisplay;

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.fasterxml.jackson.core.JsonParseException;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

public class MainActivity extends Activity {

    Bitmap image;
    BitmapDrawable bd;
    ImageView temp;
    ProgressDialog pd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        temp = (ImageView) findViewById(R.id.ivImage);

        displayImages display = new displayImages();
        display.execute();
    }

    public class displayImages extends AsyncTask <Void, Void, Bitmap>  {

        @Override
        protected Bitmap doInBackground(Void... params) {

            try {

                image = downloadBitmap("http://i1.cpcache.com/product_zoom/617914535/dickbutt_2_mug.jpg?side=Back&height=250&width=250&padToSquare=true");

            } catch (JsonParseException e) {

                e.printStackTrace();
            } catch (IOException e) {

                e.printStackTrace();
            }

            return image;
        }

        protected Void onPostExecute(Void...voids ) {
            temp.setImageBitmap(image);
            return null;

        }

    }

     private Bitmap downloadBitmap(String url) throws JsonParseException, IOException{

         // initilize the default HTTP client object
         final DefaultHttpClient client = new DefaultHttpClient();

         //forming a HttoGet request 
         final HttpGet getRequest = new HttpGet(url);

         HttpResponse response = client.execute(getRequest);

             //check 200 OK for success
             final int statusCode = response.getStatusLine().getStatusCode();

             if (statusCode != HttpStatus.SC_OK) {
                 Log.w("ImageDownloader", "Error " + statusCode + 
                         " while retrieving bitmap from " + url);
                 return null;

             }

             final HttpEntity entity = response.getEntity();
             if (entity != null) {
                 InputStream inputStream = null;
                 try {
                     // getting contents from the stream 
                     inputStream = entity.getContent();

                     // decoding stream data back into image Bitmap that android understands
                     image = BitmapFactory.decodeStream(inputStream);


                 } finally {
                     if (inputStream != null) {
                         inputStream.close();
                     }
                     entity.consumeContent();
                 }
             }

         return image;
     }
}
  • Please don't duplicate your questions (cf http://stackoverflow.com/questions/23959209). If you need to add additional information to a previous question, you can edit it. – matiash May 30 '14 at 21:11
  • It's a totally different project though and wouldn't let me delete the other one because it got an answer. – Stickerbomby May 30 '14 at 23:39

1 Answers1

0

Change your onPostExecute as so,

    //  the param type here needs to be a bitmap, 
    // and use void (not Void) as the return.
    // and add the missing @Override
    // also, no need for the return null here as well
    @Override  
    protected void onPostExecute(Bitmap image) {
        temp.setImageBitmap(image);            
    }

A good example and documentation can be found here : http://developer.android.com/reference/android/os/AsyncTask.html

petey
  • 16,914
  • 6
  • 65
  • 97
  • He's getting a `VerifyError`. This is unlikely to be the cause. – matiash May 30 '14 at 20:26
  • @matiash, since `public class displayImages extends AsyncTask ` has a result type of Bitmap, the param in `onPostExecute` should match that type. – petey May 30 '14 at 20:46
  • 1
    That is entirely correct. However that would not cause this exception. It would simply mean that you're creating another overload of onPostExecute() instead of overriding the correct one. – matiash May 30 '14 at 20:51