mardi 30 septembre 2014

Why? crashing when using condition (startsWith) with mimeType


Vote count:

-1





public class HelperUtil {

static int iconRes = R.drawable.unknown;

public static Bitmap getNestedIcon(Context context, String path) {

String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(path);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
if (type.startsWith("image")) { //crashing here
return BitmapFactory.decodeResource(context.getResources(),
R.drawable.image);
} else if (type.startsWith("audio")) { //crashing here
return BitmapFactory.decodeResource(context.getResources(),
R.drawable.audio);
} else if (type.startsWith("video")) { //crashing here
return BitmapFactory.decodeResource(context.getResources(),
R.drawable.video);
} else { //not crashing
return BitmapFactory.decodeResource(context.getResources(),
iconRes);
}
} else { //not crashing
return BitmapFactory
.decodeResource(context.getResources(), iconRes);
}

}
}


I am trying to list file with proper icon but when I used if(type.startsWith) condition it always crashing activity...I don't understand what's going on where I take wrong move? please help



asked 3 mins ago







Why? crashing when using condition (startsWith) with mimeType

Aucun commentaire:

Enregistrer un commentaire