title: JNI DETECTED ERROR IN APPLICATION: can't call void android.graphics.Canvas.drawBitmap
body: <p>all</p>
  
  <p>I try to write this code using JNI, but nothing works. Any suggestion ? </p>
  
  <pre><code>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 -&gt; FindClass("android/graphics/Canvas");
      jmethodID drawBitmapFunction = env-&gt;GetMethodID(getcanvasClass, "drawBitmap", "(Landroid/graphics/Bitmap;FFLandroid/graphics/Paint;)V");
  
     env-&gt; CallVoidMethod(getcanvasClass, drawBitmapFunction, jniBitmap-&gt;_storedBitmapPixels, width, height, paint);
  
  
  }
  </code></pre>
  
  <p>log:</p>
  
  <pre><code>[ 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&lt;android.graphics.Canvas&gt;
  
  
  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&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, 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&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, 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&amp;, _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 0000000000001238  /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
  </code></pre>
  
  <p>When I debugged the error was on this line:</p>
  
  <pre><code>env-&gt; CallVoidMethod(getcanvasClass, drawBitmapFunction, jniBitmap-&gt;_storedBitmapPixels, width - jniBitmap-&gt;_bitmapInfo.width/2,
                                                   height - jniBitmap-&gt;_bitmapInfo.height/2, paint);
  </code></pre>
  
  <p>But I don't know why, as the same code pattern using "android/graphics/Bitmap" and call createBitmap methods works fine. </p>
  
  <p>Thank you in advanced for help.</p>
  
  <p>I change the code like this:</p>
  
  <pre><code>JNIEXPORT void JNICALL
  Java_com_example_hellojni_JniBitmapHolder_drawingBitmap(JNIEnv *env, jfloat width, jfloat height, jobject canvas, jobject paint) {
  
      // TODO
      jclass getcanvasClass = env-&gt; GetObjectClass(canvas);
      jmethodID drawBitmapFunction = env -&gt; GetMethodID(getcanvasClass, "drawBitmap", "(Landroid/graphics/Bitmap;FFLandroid/graphics/Paint;)V");
  
  
      env -&gt; CallVoidMethod(canvas, drawBitmapFunction, jniBitmap-&gt;_storedBitmapPixels, width - jniBitmap-&gt;_bitmapInfo.width/2,
                           height - jniBitmap-&gt;_bitmapInfo.height/2, paint);
  
  
  }
  </code></pre>
  
  <p>log:</p>
  
  <pre><code>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&lt;android.graphics.Canvas&gt;
  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
  </code></pre>
  
  <p>Still the same error.</p>