my own android Studio Library integrating with my test phone app

Viewed 23

i created a library which im intending to create functions in it. however i met an error, the error appears at ((RCApplication)getApplicationContext()).setRosClient(client); the error states Non-static method 'getApplicationContext()' cannot be referenced from a static context but my function needs to be static in order to be used on my testing app.

public class WebSocketFunctions extends Application {

public static Context context;

public static void initializeConnection(String ip, String port, int indicator) {
    ROSBridgeClient client;
    client = new ROSBridgeClient("ws://" + ip + ":" + port);
    boolean conneSucc = client.connect(new ROSClient.ConnectionStatusListener() {
        @Override
        public void onConnect() {
            client.setDebug(true);
            Log.d(TAG,"Connect ROS success");
            ((RCApplication)getApplicationContext()).setRosClient(client); //error

        }

        @Override
        public void onDisconnect(boolean normal, String reason, int code) {
            Log.d(TAG,"ROS disconnect");
        }

        @Override
        public void onError(Exception ex) {
            ex.printStackTrace();
            Log.d(TAG,"ROS communication error");
        }
    });
}
}

this is the RCApplication

public class RCApplication extends Application {
ROSBridgeClient client;

@Override
public void onCreate() {
    super.onCreate();
}

@Override
public void onTerminate() {
    if(client != null)
        client.disconnect();
    super.onTerminate();
}

public ROSBridgeClient getRosClient() {
    return client;
}

public void setRosClient(ROSBridgeClient client) {
    this.client = client;
}
}

am i unable to getApplicationContext() in the library and Im only able to getApplicationContext() in the testing app? please advise

***NOTE: there are two apps (library & testing app) & both classes' codes shown are written in the library app.

0 Answers
Related