Android 2.2 + Textured Box throwing NoSuchMethodError

Phone: LG Optimus V

Android: 2.2.2

minSdkVersion=“8”

targetSdkVersion=“16”



Getting a java.lang.NoSuchMethodError : java.nio.Buffer.isDirect at com.jme3.util.BufferUtils.destroyDirectBuffer(BufferUtils.java:1267)

at com.jme3.renderer.android.TextureUtil.uploadBitmapAsCompressed(TextureUtil.java:107)



Code works fine when its a “mat.setColor(“Color”, ColorRGBA.Blue)” but fails when trying to use

mat.setTexture(“ColorMap”, assetManager.loadTexture(“Textures/cat1_256.png”);



I verified that the asset folder/Textures/cat1_256.png exists in the compressed apk file

Any thoughts why NoSuchMethodError would happen?





[java]import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;



public class HelloJME3 extends SimpleApplication{

@Override

public void simpleInitApp(){

Box b = new Box(Vector3f.ZERO, 1,1,1);

Geometry geom = new Geometry(“Box”,b);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

//mat.setColor(“Color”, ColorRGBA.Blue); //OLD CODE THAT WORKS

mat.setTexture(“ColorMap”, assetManager.loadTexture(“Textures/cat1_256.png”); //<


New Code
geom.setMaterial(mat);
rootNode.attachChild(geom);
}
}[/java]

good :wink:

1 Like
@gbluntzer said:
Getting a java.lang.NoSuchMethodError : java.nio.Buffer.isDirect at com.jme3.util.BufferUtils.destroyDirectBuffer(BufferUtils.java:1267)

hu! wtf?

isDirect is in java since java 6....maybe the dalvik VM for 2.2.2 was based on java 5 specs....
@nehon said:
hu! wtf?

isDirect is in java since java 6....maybe the dalvik VM for 2.2.2 was based on java 5 specs....

Its an internal and hidden method, we have to expect this every now and then :/ Also gotta check what this will be on iOS.

luckily only 15% of android users are < 2.3 now and its decreasing



http://developer.android.com/about/dashboards/index.html



can you not upgrade your phone gbluntzer? then you wont be a statistic there anymore :slight_smile:

We’re running into the same issue now. And we can’t update to 2.3, because the standard is 2.2 right now…

I really don’t know what is causing the error. Not sure if it because of Color Depth or What.

I changed the PNG to have a alpha layer in GIMP and now it works without crashing.



Maybe that will help you @robin0165

@gbluntzer said:
I really don't know what is causing the error. Not sure if it because of Color Depth or What.
I changed the PNG to have a alpha layer in GIMP and now it works without crashing.

Maybe that will help you @robin0165

That's not due to your image, that's an engine issue.
You'll have the issue elsewhere. Like with skeleton animations

This method (Buffer.isDirect) is not part of java 5 and not part of Dalvik VM for android < 2.3

Ok after some digging, it appears that java 5 Buffer class didn’t have the isDirect method…but all its sub classes did…

To quote pspeed : " Occasionally, Sun did something stupid like this."



So I made some changes to make it work on java 5 (in last svn revision).

Could you test it on your android 2.2?

3 Likes

Good job, with my optimus LG P920 3D android Version 2.2.2 , it’s working now.

Thanks

1 Like

Also Animation Works for me :slight_smile: