0

I'm developing a PhoneGap application using Javascript to communicate with Java. I'm trying to access a class called RcpApi2 within a JAR file called A100_AL1001-23_AndroidLibrary.jar, but when I try to access the functions within I get this error:

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

The errors occur when I try to access these methods:

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

Does anyone know why this is happening/how to fix this?

Project Directories:

enter image description here

Java Code:

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 File Code:

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;
     }

}
Aaron Turecki
  • 345
  • 3
  • 7
  • 24

2 Answers2

1

Those methods in RcpApi2 are not static, you must use the instance returned from RcpApi2.getInstance()

For example, change this:

RcpApi2.getInstance().setOnRcpEventListener(this);

try {
    RcpApi2.open();      

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

To this:

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

try {
    rcpAPI.open();             


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

And continue using the rcpAPI instance as the code goes along.

Hypino
  • 1,240
  • 14
  • 28
0

Is the error "Cannot make a static reference to..." a compile error? If so which line is it?

I think it basically means you are trying to access startReadTagsWithRssi() in a static way but the method isn't static. Unless you add the static modifier to startReadTagsWithRssi(), you will need to first create an instance of RcpApi2 and then call startReadTagsWithRssi() on that instance.

11th Hour Worker
  • 337
  • 3
  • 14