我有一个问题,我没有找到错误,这是我的 MainActivity 代码:
public class MainActivity extends Activity {
private static final String TAG = "odroid_weather";
private double temp1, temp2, pressure, altitude, humidity, uv;
private int visible, ir;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.weatherBoardTest();
TextView tv = new TextView(this);
tv.setText(Afficher());
setContentView(tv);
TextView temp = new TextView(this);
temp.setText((int) this.getTemperature1());
setContentView(temp);
}
static
{
System.loadLibrary("libodroid_weather");
}
public double getTemperature1() {
return temp1;
}
public double getTemperature2() {
return temp2;
}
public double getPressure() {
return pressure;
}
public double getHumidity() {
return humidity;
}
public double getAltitude() {
return altitude;
}
public double getUV() {
return uv;
}
public int getVisibleLight() {
return visible;
}
public int getInfrared() {
return ir;
}
private native String Afficher();
public native void initSerialInterface();
public native void readData();
public native void close();
static
{
System.loadLibrary("odroid_weather");
}
protected void weatherBoardTest() {
Log.d(TAG, "testing weather board");
initSerialInterface();
readData();
Log.d(TAG, "temperature1 = "+this.getTemperature1());
Log.d(TAG, "Now closing file descriptor.");
/// close();
Log.d(TAG, "finished!");
}
这是这些本机方法的 cpp 代码:
extern "C" {
void Java_com_example_assus_appweather_MainActivity_initSerialInterface(){
initSerial();
}
void Java_com_example_assus_appweather_MainActivity_close() {
close(fd);
}
void Java_com_example_assus_appweather_MainActivity_readData(JNIEnv* env, jobject thiz) {
LOGD("readData()");
我找不到错误在哪里:无法响应 JNI 函数 com.assus.appweather.MainActivity