Question

I am using Facebook's API to create a new album with a picture from my android app but I keep on getting these annoying errors that make no sense. I have done some research but have come up with nothing. Please help!

String albumName = ((TextView)findViewById(R.id.album_name)).getText().toString();
Bundle params = new Bundle();
params.putByteArray("pictures", toByteArray(mediaPath[0])); 
params.putString("name", albumName);
request.request("https://graph.facebook.com/me/albums",params,"POST", new UploadListener(), new Object());

Take a look at my log cat

01-26 15:51:50.501: W/Bundle(616): Key format expected byte[] but value was a java.lang.String. The default value was returned. 01-26 16:07:48.871: D/Facebook-Util(670): POST URL: https://graph.facebook.com/https://graph.facebook.com/me/albums 01-26 16:07:48.891: W/Bundle(670): Key format expected byte[] but value was a java.lang.String. The default value was returned. 01-26 16:07:48.891: W/Bundle(670): Attempt to cast generated internal exception: 01-26 16:07:48.891: W/Bundle(670): java.lang.ClassCastException: java.lang.String 01-26 16:07:48.891: W/Bundle(670): at android.os.Bundle.getByteArray(Bundle.java:1305) 01-26 16:07:48.891: W/Bundle(670): at com.facebook.android.Util.openUrl(Util.java:155) 01-26 16:07:48.891: W/Bundle(670): at com.facebook.android.Facebook.request(Facebook.java:717) 01-26 16:07:48.891: W/Bundle(670): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253) 01-26 16:07:49.390: D/dalvikvm(670): GC_CONCURRENT freed 2526K, 57% free 4489K/10311K, external 5789K/6493K, paused 5ms+4ms 01-26 16:07:49.560: W/Bundle(670): Key method expected byte[] but value was a java.lang.String. The default value was returned. 01-26 16:07:49.560: W/Bundle(670): Attempt to cast generated internal exception: 01-26 16:07:49.560: W/Bundle(670): java.lang.ClassCastException: java.lang.String 01-26 16:07:49.560: W/Bundle(670): at android.os.Bundle.getByteArray(Bundle.java:1305) 01-26 16:07:49.560: W/Bundle(670): at com.facebook.android.Util.encodePostBody(Util.java:63) 01-26 16:07:49.560: W/Bundle(670): at com.facebook.android.Util.openUrl(Util.java:182) 01-26 16:07:49.560: W/Bundle(670): at com.facebook.android.Facebook.request(Facebook.java:717) 01-26 16:07:49.560: W/Bundle(670): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253) 01-26 16:07:49.570: W/Bundle(670): Key format expected byte[] but value was a java.lang.String. The default value was returned. 01-26 16:07:49.570: W/Bundle(670): Attempt to cast generated internal exception: 01-26 16:07:49.570: W/Bundle(670): java.lang.ClassCastException: java.lang.String 01-26 16:07:49.570: W/Bundle(670): at android.os.Bundle.getByteArray(Bundle.java:1305) 01-26 16:07:49.570: W/Bundle(670): at com.facebook.android.Util.encodePostBody(Util.java:63) 01-26 16:07:49.570: W/Bundle(670): at com.facebook.android.Util.openUrl(Util.java:182) 01-26 16:07:49.570: W/Bundle(670): at com.facebook.android.Facebook.request(Facebook.java:717) 01-26 16:07:49.570: W/Bundle(670): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253) 01-26 16:07:49.610: D/dalvikvm(670): GC_FOR_MALLOC freed 258K, 57% free 4445K/10311K, external 5789K/6493K, paused 38ms 01-26 16:07:49.620: I/dalvikvm-heap(670): Grow heap (frag case) to 15.307MB for 2903026-byte allocation 01-26 16:07:49.670: D/dalvikvm(670): GC_FOR_MALLOC freed <1K, 45% free 7280K/13191K, external 5789K/6493K, paused 32ms 01-26 16:07:49.781: D/dalvikvm(670): GC_CONCURRENT freed 4K, 45% free 7280K/13191K, external 5789K/6493K, paused 4ms+5ms 01-26 16:07:54.990: W/dalvikvm(670): threadid=16: thread exiting with uncaught exception (group=0x40015560) 01-26 16:07:54.990: E/AndroidRuntime(670): FATAL EXCEPTION: Thread-19

Was it helpful?

Solution

Try replacing:

params.putByteArray("pictures", toByteArray(mediaPath[0]));

With:

params.putString("pictures", mediaPath[0]);

It's clearly not happy with the byte[] so that's where I'd start. (That's assuming mediaPath[] is a string array as the name suggests.

If that doesn't work, try creating the album first, then adding the pictures, check the solution here for working album creation:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top