On Sat, Aug 7, 2010 at 2:28 PM, Bret Foreman <bret.fore...@gmail.com> wrote:
> The following code does not give the expected results:
>
>                prefInputStream =
> getResources().openRawResource(R.xml.preferences);
>                byte[] rawBytes = new byte[100];
>                prefInputStream.read( rawBytes, 0, 100 );
>
> The bytes read are not printable ASCII characters. The start of the
> file looks like this:
>
> <?xml version="1.0" encoding="utf-8"?>
> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/
> android" android:key="main_preferencescreen" android:title="Settings">
>
>
> What gets read is:
>
> [3, 0, 8, 0, -8, 43, 0, 0, 1, 0, 28, 0, 0, 15, 0, 0, 100, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, -84, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0,
> 0, 24, 0, 0, 0, 42, 0, 0, 0, 70, 0, 0, 0, 94, 0, 0, 0, 116, 0, 0, 0,
> -114, 0, 0, 0, -88, 0, 0, 0, -70, 0, 0, 0, -54, 0, 0, 0, -36, 0, 0, 0,
> -12, 0, 0, 0, 8, 1, 0, 0, 26, 1, 0, 0, 114, 1, 0, 0]
>
> Any idea what might be wrong?

1. XML resources are converted into a "binary XML" format as part of
the build process.

2. XML resources are not raw resources.

Use getXml(), not getRawResource().

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

ATTENTION: Android-Beginners will be permanently disabled on August 9 2010. For 
more information about this change, please read [http://goo.gl/xkfl] or visit 
the Group home page.

Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to