Android, NetworkInfo.getTypeName(), NullpointerException

Posted by moppel on Stack Overflow See other posts from Stack Overflow or by moppel
Published on 2010-03-14T19:07:23Z Indexed on 2010/03/14 19:15 UTC
Read the original article Hit count: 299

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();
   }
  });
 }
}

© Stack Overflow or respective owner

Related posts about android

Related posts about networking