Vectors in JNI... Any Victors???

Alexander Krapf

Hi Victor,

you have more than one problem. The first is, that the Vector class does not declare a get method. You have to use elementAt instead.

The second is, that you're indeed right in assuming that you have to use the (I)Ljava/lang/Object; signature. You always have to use the exact signature of the Java method.

The third is, that you're not doing any error checking or you would have detected that the methodID is 0.

If you were using our JunC++ion tool instead, you would have imported the Vector class and your own class and generated C++ proxy bindings for them. You would then have been faced with the following native implementation task:

void _cmj_Java_some_JNI_Method( jcpp_localenv * pEnv, java::lang::Object & _this, java::util::Vector & vecStrings )
{
  java::lang::Object obj = vecStrings.elementAt( 0 );
  java::lang::String str = String::dyna_cast( obj );

  if( str != null )
  {
    //do something with it
  }
  else
    throw IllegalArgumentException( "bad vector" );
}

Much nicer, right? You can find out more about JunC++ion at http://www.codemesh.com.

Good luck,

Alex

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact