I’ve a main package named omer.ludlowcastle and another package omer.ludlowcastle.utils
I wrote this function in omer.ludlowcastle.utils :
public boolean checkInternet (){
final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
if (activeNetwork != null && activeNetwork.isConnected()) {
return true;
} else {
Toast.makeText(getApplicationContext(), "You are not connected to Internet", Toast.LENGTH_LONG).show();
return false;
}
}
and I use this function in an activity in the main package as :
public void Login (View v){
if(omer.ludlowcastle.utils.functions.checkInternet()){
//do other stuff
}
else {
//do other stuff
}
}
but the line in the braces of if gives the following error :
Cannot make a static reference to the non-static method checkInternet() from the type functions
How to solve this ?
You are getting Cannot make a static reference to the non-static method checkInternet() from the type functions because method is not static. You have 2 options:
2.Or create an object of class as
And then call method using object as
Hope it helps.