I got c++ structs in header file,
struct StatusLine
{
static jclass Class; // Lorg/apache/http/StatusLine;
static jmethodID GetStatusCode; // ()I
};
struct ByteArrayOutputStream
{
static jclass Class; // Ljava/io/ByteArrayOutputStream;
static jmethodID Constructor; // ()V
static jmethodID Close; // ()V
static jmethodID ToByteArray; // ()[B
};
struct HttpEntity
{
static jclass Class; // Lorg/apache/http/HttpEntity;
static jmethodID WriteTo; // (Ljava/io/OutputStream;)V
static jmethodID GetContent; // ()Ljava/io/InputStream;
};
and cpp file is
#define JAVA_STATUS_LINE_CLASS "org/apache/http/StatusLine"
#define JAVA_HTTP_ENTITY_CLASS "org/apache/http/HttpEntity"
#define JAVA_BYTE_ARRAY_OUTPUT_STREAM_CLASS "java/io/ByteArrayOutputStream"
jclass StatusLine::Class = 0;
jmethodID StatusLine::GetStatusCode = 0;
jclass ByteArrayOutputStream::Class = 0;
jmethodID ByteArrayOutputStream::Constructor = 0;
jmethodID ByteArrayOutputStream::Close = 0;
jmethodID ByteArrayOutputStream::ToByteArray = 0;
jclass HttpEntity::Class = 0;
jmethodID HttpEntity::WriteTo = 0;
jmethodID HttpEntity::GetContent = 0;
void initializeJniPointers()
{
StatusLine::Class = GetJniEnv()->FindClass(JAVA_STATUS_LINE_CLASS);
StatusLine::GetStatusCode = GetJniEnv()->GetMethodID(StatusLine::Class, "getStatusCode", "()I");
ByteArrayOutputStream::Class = GetJniEnv()->FindClass(JAVA_BYTE_ARRAY_OUTPUT_STREAM_CLASS);
ByteArrayOutputStream::Constructor = GetJniEnv()->GetMethodID(ByteArrayOutputStream::Class, "<init>", "()V");
ByteArrayOutputStream::Close = GetJniEnv()->GetMethodID(ByteArrayOutputStream::Class, "close", "()V");
ByteArrayOutputStream::ToByteArray = GetJniEnv()->GetMethodID(ByteArrayOutputStream::Class, "toByteArray", "()[B");
HttpEntity::Class = GetJniEnv()->FindClass(JAVA_HTTP_ENTITY_CLASS);
HttpEntity::WriteTo = GetJniEnv()->GetMethodID(HttpEntity::Class, "writeTo", "(Ljava/io/OutputStream;)V");
HttpEntity::GetContent = GetJniEnv()->GetMethodID(HttpEntity::Class, "getContent", "()Ljava/io/InputStream;");
}
function initializeJniPointers() crushes on line StatusLine::GetStatusCode = GetJniEnv()->GetMethodID(); because StatusLine::Class is NULL. But! I notice that: If I write this in some java file of the project StatusLine l = new StatuLine() { ... }
Function crushes on ByteArrayOutputStream::Constructor because ByteArrayOutputStream::Class is NULL, if I create an object of ByteArrayOutputStream in java, function will go further to the next object, etc... I notice that: If I just declare a variable of ByteArrayOutputStream, findClass will return NULL.
Could someone explain me what to do? BTW I use Android 2.3.5 device Samsung GT-S5363, I tried other vertions of android (elder) and devices and it works fine.