Reputation: 69
I am trying to get network connectivity in my app. My compile version is 23 and target version is 19. Every thing works fine when I run my app on device with api version 23. But I get error "Could not find method android.content.Context.getSystemService" when I run my app on device with api version 19.
public class LoadingActivity extends AppCompatActivity {
private String TAG = LoadingActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loading);
Log.d(TAG,"onCreate()");
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG,"onStart()");
ConnectivityManager cm = (ConnectivityManager)getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
Boolean isConnected = (activeNetwork != null && activeNetwork.isConnectedOrConnecting());
}
}
partial stacktrace
06-03 00:23:36.439 1479-1479/com.example.andonsystem D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
06-03 00:23:36.447 1479-1479/com.example.andonsystem D/LoadingActivity: onCreate()
06-03 00:23:36.447 1479-1479/com.example.andonsystem D/LoadingActivity: onStart()
06-03 00:23:36.499 1479-1484/com.example.andonsystem D/dalvikvm: GC_CONCURRENT freed 271K, 10% free 2976K/3292K, paused 2ms+1ms, total 8ms
06-03 00:23:36.503 522-851/system_process I/ActivityManager: START u0 {cmp=com.example.andonsystem/.LoginActivity} from pid 1479
06-03 00:23:37.015 1479-1479/com.example.andonsystem I/dalvikvm: Could not find method android.content.Context.getSystemService, referenced from method com.example.andonsystem.LoginActivity.access$super
06-03 00:23:37.015 1479-1479/com.example.andonsystem W/dalvikvm: VFY: unable to resolve virtual method 473: Landroid/content/Context;.getSystemService (Ljava/lang/Class;)Ljava/lang/Object;
06-03 00:23:37.015 1479-1479/com.example.andonsystem D/dalvikvm: VFY: replacing opcode 0x6f at 0x004b
thanks for help in advance...
Upvotes: 0
Views: 1956
Reputation: 304
This apparently means that the Android is attempting to invoke methods that exist on the newer target Android version that do not exist on the older API level. The OS is informing you that it is substituting methods. In general, the app will continue to run properly, unless there are no compatible substitution methods. The appcompat library is supposed to provide these substitutions.
Upvotes: 0
Reputation: 2019
Looks like you're importing the wrong Context class. The package is android.content.Context
. (so the fully qualified method would be android.content.Context.getSystemService()
)
Upvotes: 1