Java code:
package local.ttt;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
public class Text2Bitmap {
static Bitmap getBitmap(String text,int fontsize) {
Paint paint=new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(fontsize);
paint.setAntiAlias(true);
paint.setTypeface(Typeface.DEFAULT);
int outwidth=(int)Math.round(paint.measureText(text));
Bitmap bitmap=Bitmap.createBitmap(outwidth,fontsize,Bitmap.Config.ALPHA_8);
Canvas canvas=new Canvas(bitmap);
canvas.drawText(text,0,fontsize-1,paint);
return bitmap;
}
}
C source:
...
MY_ASSERT(vm_cached!=NULL);
JNIEnv* env;
jint res=vm_cached->AttachCurrentThread(&env,NULL);
MY_ASSERT(res==0);
jclass activityClass=env->FindClass("android/app/NativeActivity");
MY_ASSERT(activityClass!=NULL);
jmethodID getClassLoader=env->GetMethodID(activityClass,"getClassLoader","()Ljava/lang/ClassLoader;");
MY_ASSERT(getClassLoader!=NULL);
MY_ASSERT(nativeActivityObjHnd!=NULL);
jobject cls=env->CallObjectMethod(nativeActivityObjHnd,getClassLoader);
jclass classLoader=env->FindClass("java/lang/ClassLoader");
MY_ASSERT(classLoader!=NULL);
jmethodID findClass=env->GetMethodID(classLoader,"loadClass","(Ljava/lang/String;)Ljava/lang/Class;");
MY_ASSERT(findClass!=NULL);
jstring strClassName=env->NewStringUTF("Llocal/ttt/Text2Bitmap;");
jclass text2bitmapClass=(jclass)env->CallObjectMethod(cls,findClass,strClassName); //fails here
MY_ASSERT(text2bitmapClass!=NULL);
res=vm_cached->DetachCurrentThread();
MY_ASSERT(res==0);
...
it fails with:
W/dalvikvm(5614): dvmFindClassByName rejecting 'Llocal/ttt/Text2Bitmap;' W/dalvikvm(5614): threadid=9: thread exiting with uncaught exception (group=0x4002d560) E/AndroidRuntime(5614): FATAL EXCEPTION: Thread-10 E/AndroidRuntime(5614): java.lang.ClassNotFoundException: Llocal/ttt/Text2Bitmap; in loader dalvik.system.PathClassLoader[.] E/AndroidRuntime(5614): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) E/AndroidRuntime(5614): at java.lang.ClassLoader.loadClass(ClassLoader.java:551) E/AndroidRuntime(5614): at java.lang.ClassLoader.loadClass(ClassLoader.java:511) E/AndroidRuntime(5614): at dalvik.system.NativeStart.run(Native Method)
Any hint what I'm doing wrong, please?