Android, NetworkInfo.getTypeName(), NullpointerException
- by moppel
I have an activity which shows some List entries. When I click on a list item my app checks which connection type is available ("WIF" or "MOBILE"), through NetworkInfo.getTypeName(). As soon as I call this method I get a NullpointerException. Why? 
I tested this on the emulator, cause my phone is currently not available (it's broken...). I assume this is the problem? This is the only explanation that I have, if that's not the case I have no idea why this would be null.
Here's some code snippet:
public class VideoList extends ListActivity{
 ...
 public void onCreate(Bundle bundle){
  final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  ...
  listview.setOnItemClickListener(new OnItemClickListener(){
   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ...
    NetworkInfo ni = cm.getActiveNetworkInfo();
    String connex = ni.getTypeName(); //Nullpointer exception here
    if(connex.equals("WIFI")doSomething();
   }
  });
 }
}