gpt4 book ai didi

java - 访问 .jar API 函数 - 错误 : Cannot make a static reference to the non-static method

转载 作者:行者123 更新时间:2023-12-01 12:39:15 25 4
gpt4 key购买 nike

我正在开发一个 PhoneGap 应用程序,使用 Javascript 与 Java 进行通信。我正在尝试访问名为 A100_AL1001-23_AndroidLibrary.jar 的 JAR 文件中名为 RcpApi2 的类,但是当我尝试访问其中的函数时,出现此错误:

Cannot make a static reference to the non-static method startReadTagsWithRssi(int, int,  int) from the type RcpApi2

当我尝试访问这些方法时发生错误:

  • RcpApi2.open();
  • RcpApi2.isopen;
  • RcpApi2.startReadTagsWithRssi(...);

有谁知道为什么会发生这种情况/如何解决这个问题?

项目目录:

enter image description here

Java 代码:

import com.phychips.rcp.*;

public class HelloPlugin extends Plugin implements iRcpEvent2 {

public static final String KEY_ENCODING = "my_encoding";
public static final String KEY_SAVELOG = "my_saveLog";
public static final String NATIVE_ACTION_STRING="nativeAction";
public static final String SUCCESS_PARAMETER="success";
...

public PluginResult execute(String action, JSONArray dataArray, String callbackId) {

if (NATIVE_ACTION_STRING.equals(action)) {

String resultType = null;
try {
resultType = dataArray.getString(0);
}
catch (Exception ex) {
Log.d("HelloPlugin", ex.toString());
}

if (resultType.equals(SUCCESS_PARAMETER)) {

RcpApi2.getInstance().setOnRcpEventListener(this);

try {
RcpApi2.open();


} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if (RcpApi2.isOpen)
{
try {
boolean k = RcpApi2.startReadTagsWithRssi(maxTags, maxTime, repeatCycle);
return new PluginResult(PluginResult.Status.OK, "Yay, Success!!!");

} catch (RcpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Jar 文件代码:

public class RcpApi2 extends BroadcastReceiver {

private boolean isOpen = false;

public boolean open() throws Exception {
init(mIoType);
readerIo.open();
isOpen = true;
}

public boolean isOpen() {
return this.isOpen;
}

public boolean startReadTagsWithRssi(int maxTags, int maxTime, int repeatCycle) {
RcpPacket rcpPacket = RcpPacket.getInstance();
if (!this.mIRcp.startReadTagsWithRssi(rcpPacket, maxTags, maxTime, repeatCycle)) {
return false;
}
boolean ret = true;
...
return ret;
}

}

最佳答案

RcpApi2中的那些方法不是静态的,您必须使用从RcpApi2.getInstance()返回的实例

例如,更改此:

RcpApi2.getInstance().setOnRcpEventListener(this);

try {
RcpApi2.open();

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

对此:

RCPApi2 rcpAPI = RCPApi2.getInstance();
rcpAPI.setOnRcpEventListener(this);

try {
rcpAPI.open();


} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

并随着代码的进行继续使用 rcpAPI 实例。

关于java - 访问 .jar API 函数 - 错误 : Cannot make a static reference to the non-static method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25275850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com