を呼び出すことはできませんすべてのJNIは、アプリケーションでエラーを検出します。void android.graphics.Canvas.drawBitmap
私はJNIを使用してこのコードを書いてみるが、何も動作します。なにか提案を ?
extern "C"
{
JNIEXPORT void JNICALL Java_com_example_hellojni_HelloView_drawingBitmap(JNIEnv *env, jfloat width, jfloat height, jobject canvas, jobjectRefType paint);
}
class JniBitmap
{
public:
uint32_t* _storedBitmapPixels;
AndroidBitmapInfo _bitmapInfo;
JniBitmap()
{
_storedBitmapPixels = NULL;
}
};
JniBitmap *jniBitmap = new JniBitmap();
JNIEXPORT void JNICALL Java_com_example_hellojni_HelloView_drawingBitmap(JNIEnv *env, jfloat width, jfloat height, jobject canvas, jobjectRefType paint){
jclass getcanvasClass = env -> FindClass("android/graphics/Canvas");
jmethodID drawBitmapFunction = env->GetMethodID(getcanvasClass, "drawBitmap", "(Landroid/graphics/Bitmap;FFLandroid/graphics/Paint;)V");
env-> CallVoidMethod(getcanvasClass, drawBitmapFunction, jniBitmap->_storedBitmapPixels, width, height, paint);
}
ログ:私はエラーがこの行にあったデバッグ
[ 07-23 13:22:44.849 24629:24890 D/ ]
ro.exynos.dss isEnabled: 0
07-23 13:22:44.849 24629-24890/com.example.hellojni D/mali_winsys: new_window_surface returns 0x3000, [1440x2560]-format:1
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410]
JNI DETECTED ERROR IN APPLICATION: can't call void android.graphics.Canvas.drawBitmap(android.graphics.Bitmap, float, float, android.graphics.Paint) on instance of java.lang.Class<android.graphics.Canvas>
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] in call to CallVoidMethodV
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] from void com.example.hellojni.HelloView.drawingBitmap(float, float, android.graphics.Canvas, android.graphics.Paint)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] "Thread-1691" prio=5 tid=10 Runnable
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] | group="main" sCount=0 dsCount=0 obj=0x12c84940 self=0x7faba89a00
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] | sysTid=24889 nice=0 cgrp=default sched=0/0 handle=0x7fabbfd440
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] | state=R schedstat=(57509155 44992191 10) utm=5 stm=0 core=4 HZ=100
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] | stack=0x7fabafb000-0x7fabafd000 stackSize=1037KB
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] | held mutexes= "mutator lock"(shared held)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #00 pc 000000000048a5b0 /system/lib64/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, BacktraceMap*, char const*, art::ArtMethod*, void*)+200)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #01 pc 0000000000459358 /system/lib64/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, BacktraceMap*) const+224)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #02 pc 000000000030d764 /system/lib64/libart.so (art::JavaVMExt::JniAbort(char const*, char const*)+1004)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #03 pc 000000000030e01c /system/lib64/libart.so (art::JavaVMExt::JniAbortV(char const*, char const*, std::__va_list)+116)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #04 pc 000000000014217c /system/lib64/libart.so (art::ScopedCheck::AbortF(char const*, ...)+144)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #05 pc 0000000000142574 /system/lib64/libart.so (art::ScopedCheck::CheckMethodAndSig(art::ScopedObjectAccess&, _jobject*, _jclass*, _jmethodID*, art::Primitive::Type, art::InvokeType)+724)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #06 pc 000000000015bc58 /system/lib64/libart.so (art::CheckJNI::CallMethodV(char const*, _JNIEnv*, _jobject*, _jclass*, _jmethodID*, std::__va_list, art::Primitive::Type, art::InvokeType)+724)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #07 pc 000000000015def8 /system/lib64/libart.so (art::CheckJNI::CallVoidMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::__va_list)+68)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #08 pc 00000000000013a0 /data/app/com.example.hellojni-2/lib/arm64/libJniBitmapOperations.so (_JNIEnv::CallVoidMethod(_jobject*, _jmethodID*, ...)+192)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #09 pc 00000000000/data/app/com.example.hellojni-2/lib/arm64/libJniBitmapOperations.so (Java_com_example_hellojni_HelloView_drawingBitmap+200)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #10 pc 0000000000003ae0 /data/app/com.example.hellojni-2/oat/arm64/base.odex (void com.example.hellojni.HelloView.drawingBitmap(float, float, android.graphics.Canvas, android.graphics.Paint)+196)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #11 pc 000000000000397c /data/app/com.example.hellojni-2/oat/arm64/base.odex (void com.example.hellojni.HelloView.draw()+624)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #12 pc 0000000000003e10 /data/app/com.example.hellojni-2/oat/arm64/base.odex (void com.example.hellojni.HelloView.run()+132)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] native: #13 pc 0000000002f4e654 /system/framework/arm64/boot.oat (???)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] at com.example.hellojni.HelloView.drawingBitmap(Native method)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] at com.example.hellojni.HelloView.draw(HelloView.java:80)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] at com.example.hellojni.HelloView.run(HelloView.java:48)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] at java.lang.Thread.run(Thread.java:818)
07-23 13:22:44.869 24629-24889/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410]
07-23 13:22:44.899 24629-248
:同じコードパターンがアンドロイド」を使用して、なぜ、
env-> CallVoidMethod(getcanvasClass, drawBitmapFunction, jniBitmap->_storedBitmapPixels, width - jniBitmap->_bitmapInfo.width/2,
height - jniBitmap->_bitmapInfo.height/2, paint);
しかし、私は知りません/グラフィックス/ビットマップ "を呼び出し、createBitmapメソッドを呼び出しても問題ありません。
ありがとうございました。
私はこのようなコード変更:
JNIEXPORT void JNICALL
Java_com_example_hellojni_JniBitmapHolder_drawingBitmap(JNIEnv *env, jfloat width, jfloat height, jobject canvas, jobject paint) {
// TODO
jclass getcanvasClass = env-> GetObjectClass(canvas);
jmethodID drawBitmapFunction = env -> GetMethodID(getcanvasClass, "drawBitmap", "(Landroid/graphics/Bitmap;FFLandroid/graphics/Paint;)V");
env -> CallVoidMethod(canvas, drawBitmapFunction, jniBitmap->_storedBitmapPixels, width - jniBitmap->_bitmapInfo.width/2,
height - jniBitmap->_bitmapInfo.height/2, paint);
}
ログ:
07-23 21:44:41.539 17369-17369/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: can't call void android.graphics.Canvas.drawBitmap(android.graphics.Bitmap, float, float, android.graphics.Paint) on instance of java.lang.Class<android.graphics.Canvas>
07-23 21:44:41.539 17369-17369/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] in call to CallVoidMethodV
07-23 21:44:41.539 17369-17369/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] from void com.example.hellojni.JniBitmapHolder.drawingBitmap(float, float, android.graphics.Canvas, android.graphics.Paint)
07-23 21:44:41.539 17369-17369/com.example.hellojni A/art: art/runtime/java_vm_ext.cc:410] "main" prio=5 tid=1 Runnable
それでも同じエラーが。
ありがとうございますが、エラーは引き続き発生します。いくつかのコード例を手伝ってもらえますか?ありがとう –
あなたのC++コードは今見た目に見えます。何がうまくいかないでしょうか?おそらく、あなたのapkはまだ古いライブラリを使用しています。これを確認するためにいくつかのログステートメントを追加してください。おそらく、JniBitmapHolder.drawingBitmap()を呼び出すJava側が正しくない可能性があります。 –