Java代码:
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源:
...
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);
...
它失败了:
W/dalvikvm(5614): dvmFindClassByName 拒绝 'Llocal/ttt/Text2Bitmap;' W/dalvikvm(5614): threadid=9: 线程以未捕获的异常退出 (group=0x4002d560) E/AndroidRuntime(5614):致命异常:线程 10 E/AndroidRuntime(5614): java.lang.ClassNotFoundException: Llocal/ttt/Text2Bitmap; 在加载器 dalvik.system.PathClassLoader[.] E/AndroidRuntime(5614):在 dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) E/AndroidRuntime(5614): 在 java.lang.ClassLoader.loadClass(ClassLoader.java:551) E/AndroidRuntime(5614):在 java.lang.ClassLoader.loadClass(ClassLoader.java:511) E/AndroidRuntime(5614): 在 dalvik.system.NativeStart.run(Native Method)
请问有什么提示我做错了吗?