Actually, the explanation here is incorrect. You CAN cast from Integer to int, or Double to double, or Boolean to boolean. In fact, the compiler will even do it for you these days.
However, those are specific cases of related types. There is no relationship whatsoever between the types Bitmap and byte[]. The reason for the confusion is no doubt C++, where the 'cast' operator is also a coercion operator that can be overridden. That's a peculiarity of C++. On Apr 5, 5:00 am, "Mark Murphy" <[email protected]> wrote: > > I'm trying to draw an image downloaded from the web but keep getting > > the error "Cannot cast from Bitmap to byte[]". Here's the code > > snippet: > > > BufferedInputStream bis = new > > BufferedInputStream(somethingdownloaded); > > DataInputStream dis = new DataInputStream(bis); > > Bitmap image; > > > dis.read((byte[]) image); // "Error: cannot cast" > > > What am I doing wrong? > > First, image has not even been initialized, so you could not read from it > in any case. > > Second, you can't cast from Bitmap to byte[], for the same reason you > cannot cast from Integer to int, or Double to double, or Boolean to > boolean. You cannot cast from an Object to a primitive. > > Use BitmapFactory.decodeStream(). > > -- > Mark Murphy (a Commons Guy)http://commonsware.com > Android App Developer Books:http://commonsware.com/books.html -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe, reply using "remove me" as the subject.

