Jary
Jary

Reputation: 1521

Android JNI: FindClass() cannot find my class

I am trying to use FindClass on one of my Java file in Android, but it never finds the class.

I use the following code (C++):

jclass clsLocal = env->FindClass("com/device/client/HostConnection");

In Eclipse, in src, I have the package com.device.client and the file HostConnection.java in it.

It seems to me that the error has to do with the -classpath. I am not completely sure if that is the problem though. This is a cat of .classpath generated by Eclipse:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

The directory src/ contains the directory com/, which contains device/, which contains client/:

rudys@rudys-N61Jq:~/workspace/DeviceClient/src/com/device/client$ ls
HostConnection.java  Main.java  ServerConnection.java  SettingsLayout.java

I tried to create a rule in the .classpath such as:

<classpathentry kind="src" path="src/com/device/client"/>

but Eclipse spots it as a problem (nested with src/), so I believe the path="src/" already takes care of all those subdirectories.

I am not sure what it is not working.

Could anyone please help me?

Upvotes: 1

Views: 3725

Answers (1)

Jary
Jary

Reputation: 1521

The problem was that I was starting a new thread, and running the code in that thread.

I should have gotten the class inside the function from Java, and that works well.

Upvotes: 1

Related Questions