Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nullpointerexception getSystemService

Tags:

android

Following line will only not result in a nullpointer exception if I'm connected to a WLAN:

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

Otherwise I get a nullpointer-exception straight ahead? How can I fix this? I want my background service to only work, when it is connected to wlan. But that Nullpointerexception just kills the whole app...

like image 948
user283494 Avatar asked Nov 27 '22 12:11

user283494


1 Answers

Add to the manifest the following line:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
like image 159
Macarse Avatar answered Dec 10 '22 02:12

Macarse