jeudi 18 février 2016

Android: NullpointerException in if else statement

This is kinda my first project to work on and i'm having a minor issue here that i want help with , so i made a list that contains all of the Countries barcodes and i want to make them appear in my textview so here is a sample of the code it's very simple :

public class Pays {
    public String RetournePays(Integer test) {       
        if (test != null){
        else  if ((test >= 0) && (test <= 13))
            return ("USA and Canada");
        else if ((test >= 20) && (test <= 29))
            return ("internal use");
        else if ((test >= 30) && (test <= 37))
            return ("France");
        else return "unknown"
    }
}

but it always gives me nullpointerexception when i try to call the RetournePays function , can someone tell me why ?

and this is how i call it :

String H = "" + getIntent().getStringExtra("Text");
String up = H.substring(0, Math.min(H.length(), 3));
Integer foo = Integer.valueOf(up);
String D = K.RetournePays(foo);

when i run it , it always gives me nullpointer ,Please help me :(

Aucun commentaire:

Enregistrer un commentaire