1

Here is my log cat. Unfortunately I am not a pro in reading errors from logcat so please help me :)

05-30 12:12:16.510: I/System.out(838):  We made it this far 1
05-30 12:12:17.230: I/System.out(838):  We made it this far 2
05-30 12:12:17.240: W/dalvikvm(838): VFY: unable to resolve exception class 748 (Lcom/fasterxml/jackson/core/JsonParseException;)
05-30 12:12:17.240: W/dalvikvm(838): VFY: unable to find exception handler at addr 0x2a
05-30 12:12:17.240: W/dalvikvm(838): VFY:  rejected Lcom/example/bitmapdisplay/MainActivity$URLArray;.doInBackground ([Ljava/lang/Void;)Ljava/lang/Void;
05-30 12:12:17.240: W/dalvikvm(838): VFY:  rejecting opcode 0x0d at 0x002a
05-30 12:12:17.250: W/dalvikvm(838): VFY:  rejected Lcom/example/bitmapdisplay/MainActivity$URLArray;.doInBackground ([Ljava/lang/Void;)Ljava/lang/Void;
05-30 12:12:17.250: W/dalvikvm(838): Verifier rejected class Lcom/example/bitmapdisplay/MainActivity$URLArray;
05-30 12:12:17.250: D/AndroidRuntime(838): Shutting down VM
05-30 12:12:17.250: W/dalvikvm(838): threadid=1: thread exiting with uncaught exception (group=0xb1adaba8)
05-30 12:12:17.270: E/AndroidRuntime(838): FATAL EXCEPTION: main
05-30 12:12:17.270: E/AndroidRuntime(838): Process: com.example.bitmapdisplay, PID: 838
05-30 12:12:17.270: E/AndroidRuntime(838): java.lang.VerifyError: com/example/bitmapdisplay/MainActivity$URLArray
05-30 12:12:17.270: E/AndroidRuntime(838):  at com.example.bitmapdisplay.MainActivity.onCreate(MainActivity.java:72)
05-30 12:12:17.270: E/AndroidRuntime(838):  at android.app.Activity.performCreate(Activity.java:5231)
05-30 12:12:17.270: E/AndroidRuntime(838):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-30 12:12:17.270: E/AndroidRuntime(838):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-30 12:12:17.270: E/AndroidRuntime(838):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-30 12:12:17.270: E/AndroidRuntime(838):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-30 12:12:17.270: E/AndroidRuntime(838):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-30 12:12:17.270: E/AndroidRuntime(838):  at android.os.Handler.dispatchMessage(Handler.java:102)
05-30 12:12:17.270: E/AndroidRuntime(838):  at android.os.Looper.loop(Looper.java:136)
05-30 12:12:17.270: E/AndroidRuntime(838):  at android.app.ActivityThread.main(ActivityThread.java:5017)
05-30 12:12:17.270: E/AndroidRuntime(838):  at java.lang.reflect.Method.invokeNative(Native Method)
05-30 12:12:17.270: E/AndroidRuntime(838):  at java.lang.reflect.Method.invoke(Method.java:515)
05-30 12:12:17.270: E/AndroidRuntime(838):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-30 12:12:17.270: E/AndroidRuntime(838):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-30 12:12:17.270: E/AndroidRuntime(838):  at dalvik.system.NativeStart.main(Native Method)
05-30 12:12:30.390: I/Process(838): Sending signal. PID: 838 SIG: 9

Here is the logcat code and here is my Java code. It seems like the problems are coming from the thread URLArray because, as seen in the logcat, the system doesn't even print the third "we made it this far":

package com.example.bitmapdisplay;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;

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.R;
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.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;


public class MainActivity extends Activity {

    /**
     * Bitmap items na dimage displaying
     */
    Bitmap image;
    BitmapDrawable bd;
    ImageView temp;
    ProgressDialog pd;

    /**
     * JSON URL
     */
    URL url;

    /**
     * Data from JSON file
     */
    ArrayList<String> urls;
    ArrayList<ImageView> images;

    JsonParsing obj;

    String json_link_str = "http://api.tumblr.com/v2/blog/humansofnewyork.com/posts?api_key=7ag2CJXOuxuW3vlVS5wQG6pYA6a2ZQcSCjzZsAp2pDbVwf3xEk&notes_info=true&filter=text";
    int counter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        System.out.println(" We made it this far 1");
        super.onCreate(savedInstanceState);
        setContentView(com.example.bitmapdisplay.R.layout.image_container);

        counter = 0;
        images = new ArrayList<ImageView>();
        urls = new ArrayList<String>();

        System.out.println(" We made it this far 2");

        new URLArray().execute();


    }

    /**
     * Fills the ListView
     */
    private void fillGridView() {

        ArrayAdapter<ImageView> adapter = new ArrayAdapter<ImageView>(this, com.example.bitmapdisplay.R.layout.image_container,images);

        GridView grid = (GridView) findViewById(com.example.bitmapdisplay.R.id.gvImages);

        grid.setAdapter(adapter);

    }

    public class URLArray extends AsyncTask<Void, Void, Void                                                                                                                                         > {

        public URLArray() {

        }

        @Override
        protected Void doInBackground(Void...params ) {
            try {
                System.out.println(" We made it this far 3");

                URL json_link = new URL(json_link_str);

                JsonParsing parse_images = new JsonParsing(json_link);

                    try {
                        parse_images.parseFile(3, urls);
                        System.out.println(" We made it this far 4");

                    } catch (JsonParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    obj = parse_images;
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(Void arg) {
            super.onPreExecute();
            System.out.println(" We made it this far 5");

            urls = obj.getURLs();
            new TheTask().execute();
        }

    }


class TheTask extends AsyncTask<Void,Void,Void>
{


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

        System.out.println(" We made it this far 6");

        pd = new ProgressDialog(MainActivity .this);
        pd.show();


        System.out.println(" We made it this far 7");

        try
        {
            int counter = 0;
        for (ImageView temp : images) {

            image = downloadBitmap(urls.get(counter));
            temp.setImageBitmap(image);
            images.add(temp);
            counter++;
        }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        System.out.println(" We made it this far 8");

        super.onPostExecute(result);
        pd.dismiss();
        if(image!=null)
        {
            fillGridView();
        }

    }   
}
 private Bitmap downloadBitmap(String url) {
     // initilize the default HTTP client object
     final DefaultHttpClient client = new DefaultHttpClient();

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

         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();
             }
         }
     } catch (Exception e) {
         // You Could provide a more explicit error message for IOException
         getRequest.abort();
         Log.e("ImageDownloader", "Something went wrong while" +
                 " retrieving bitmap from " + url + e.toString());
     } 

     return image;
 }


}
matiash
  • 54,791
  • 16
  • 125
  • 154
  • Why do you have the empty `URLArray()` constructor? What happens if you take that out? – Adam Johns May 30 '14 at 16:46
  • There was a problem when the `JsonParseException` class was loaded by the runtime. See http://stackoverflow.com/questions/100107/reasons-of-getting-a-java-lang-verifyerror for possible reasons. Most likely you're using the wrong version of a library. – matiash May 30 '14 at 16:51
  • @AdamJohns I changed that. No difference :/ – Stickerbomby May 30 '14 at 17:33
  • @matiash I see. However, where would I change the library that is at runtime? I'm sorry, I'm bad at using logcat to identify where and which package exactly is the problem. – Stickerbomby May 30 '14 at 18:53
  • The problem is probably related to the jars used as libs. See http://stackoverflow.com/questions/6247862/getting-caused-by-java-lang-verifyerror for possible solutions – matiash May 30 '14 at 20:12

1 Answers1

0

The key problem is here

05-30 12:12:17.240: W/dalvikvm(838): VFY: unable to resolve exception class 748 (Lcom/fasterxml/jackson/core/JsonParseException;)
05-30 12:12:17.240: W/dalvikvm(838): VFY: unable to find exception handler at addr 0x2a
05-30 12:12:17.240: W/dalvikvm(838): VFY:  rejected Lcom/example/bitmapdisplay/MainActivity$URLArray;.doInBackground ([Ljava/lang/Void;)Ljava/lang/Void;
05-30 12:12:17.240: W/dalvikvm(838): VFY:  rejecting opcode 0x0d at 0x002a
05-30 12:12:17.250: W/dalvikvm(838): VFY:  rejected Lcom/example/bitmapdisplay/MainActivity$URLArray;.doInBackground ([Ljava/lang/Void;)Ljava/lang/Void;
05-30 12:12:17.250: W/dalvikvm(838): Verifier rejected class Lcom/example/bitmapdisplay/MainActivity$URLArray;

and it all goes downhill from there.

Looks like JsonParseException (and possibly other classes from Jackson) are not being included in your APK. This could happen if they're not being exported by Eclipse.

Instead of adding it as an external library, just place jackson-core-x.x.x.jar in the libs folder of your Android project and it should be enough to ensure this.

matiash
  • 54,791
  • 16
  • 125
  • 154