Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VFY: unable to resolve virtual method

I am using Jackson in my android app.

I have added these two jars in my build-path:

jackson-core-asl-1.0.0.jar
jackson-mapper-asl-1.0.0.jar

But, I keep seeing this in my Logcat:

11-24 18:25:15.093: I/dalvikvm(28842): Could not find method org.codehaus.jackson.map.ObjectMapper.getTypeFactory, referenced from method org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.getJavaType
11-24 18:25:15.093: W/dalvikvm(28842): VFY: unable to resolve virtual method 17967: Lorg/codehaus/jackson/map/ObjectMapper;.getTypeFactory ()Lorg/codehaus/jackson/map/type/TypeFactory;

It's only on that method. I have searched StackOverflow on similar errors, but all of them were:

  • Libraries wrong versions (mine are correct)
  • Libraries not in /libs but in /lib (i have them in /libs)

My Android version is 4.0.3. I am using this in combination with Spring Android libraries.

like image 288
tolgap Avatar asked Nov 24 '12 17:11

tolgap


3 Answers

I had a similar problem; assuming you're using Eclipse, try the following:

  1. Right click on your project
  2. Go to Build Path > Configure Build Path...
  3. Click on the "Order and Export" tab
  4. Check the boxes next to your jars, then click OK
  5. Clean and Build your project, then see if it works.

Hopefully that works.

like image 196
Erhannis Avatar answered Oct 18 '22 03:10

Erhannis


This can also happen if you have code calling methods that don't exist in the current device OS version.

For example, if somewhere in your app you call Settings.Global.getFloat(String) - which was added in api 17 - and the current device is running api 15, you will see this warning in your logs.

There will be a crash if you actually try to invoke this method. There is no problem if you don't call this method. So make sure you always check the current version before calling this.

    private float getAnimationSetting(ContentResolver contentResolver,
                                      String setting) throws Settings.SettingNotFoundException {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return getAnimationSettingJB(contentResolver, setting);
        } else {
            return getAnimationSettingLegacy(contentResolver, setting);
        }
    }

    private float getAnimationSettingLegacy(ContentResolver contentResolver,
                                            String setting) throws Settings.SettingNotFoundException {
        return Settings.System.getFloat(contentResolver, setting);
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    private float getAnimationSettingJB(ContentResolver contentResolver,
                                        String setting) throws Settings.SettingNotFoundException {
        return Settings.Global.getFloat(contentResolver, setting);
    }
like image 28
Pedro Loureiro Avatar answered Oct 18 '22 03:10

Pedro Loureiro


In my case, this solution cannot work.
Check the code format of jar file is fit as JDK 1.6,
I found this issue via changing my lib code format from 1.7 to 1.6, and this issue would be solved.

  1. To add a external jar on eclipse for Android Project, we can do as this :
    . Project properties -> Java Build Path -> Libraries then add those External Jar file.
    . Project properties -> Java Build Path -> Order & Export then checked those External Jar file.
    You can clean & re-build the target project to see the apk file size and test those functions in external jar.

  2. To add a external jar on eclipse for Android Project, we can do as this :
    . copy the jar file to libs of android project, and done.

    For #1, it is easy to handle multi-projects for one libs.
    For #2, it is easy to use and no configure required.

    That's all.
like image 1
Leo Chen Avatar answered Oct 18 '22 03:10

Leo Chen