Magic number exception

Put your problem here if it does not fit any of the other categories.

Magic number exception

Postby chippie2000 » Wed Apr 06, 2011 9:24 pm

Hi guys, I'm trying to parcel up the location object and its throwning a "magic number exception when attempting to unparcel it. I've got the following...

Code: Select all

package com.john.scratchpad;

import android.location.Location;
import android.os.Parcel;
import android.os.Parcelable;

public class BitmapClass implements Parcelable {

   public Location location;

   @Override
   public int describeContents() {
      return 0;
   }

   @Override
   public void writeToParcel(Parcel dest, int flags) {
      dest.writeParcelable(location, flags);
   }
   
   
   public BitmapClass(Location location) {
      this.location = location;
   }

   public static final Parcelable.Creator<BitmapClass> CREATOR = new Parcelable.Creator<BitmapClass>() {

      @Override
      public BitmapClass createFromParcel(Parcel source) {
         return new BitmapClass(Location.CREATOR.createFromParcel(source));
      }

      @Override
      public BitmapClass[] newArray(int size) {
         return new BitmapClass[size];
      }
   };
}


and in my unit test ive got

Code: Select all

package com.john.scratchpad.test;

import android.location.Location;
import android.os.Parcel;
import android.test.AndroidTestCase;

public class BitmapClassTest extends AndroidTestCase{

   public void testCreator() {
      
      //bit.bitmap = new Bitmap();
      Location location = new Location("h");
      location.setLatitude(222.0);
      location.setLongitude(20.254);
      location.setAccuracy(10.10f);
      location.setBearing(10.10f);
      location.setProvider("");
      location.setSpeed(200f);
      location.setTime(123456);
      
      
      Parcel e = Parcel.obtain();
      e.writeParcelable(location,0);
      Location location2 = Location.CREATOR.createFromParcel(e);
      assertNotNull(location2);
      assertEquals(location.getLatitude(), location2.getLatitude());
   }
}


Now I'm getting the following exception whenI run my test...


04-06 21:19:38.927: ERROR/Bundle(2348): readBundle: bad magic number
04-06 21:19:38.947: ERROR/Bundle(2348): readBundle: trace = java.lang.RuntimeException
04-06 21:19:38.947: ERROR/Bundle(2348): at android.os.Parcel.readBundle(Parcel.java:1363)
04-06 21:19:38.947: ERROR/Bundle(2348): at android.os.Parcel.readBundle(Parcel.java:1345)
04-06 21:19:38.947: ERROR/Bundle(2348): at android.location.Location$1.createFromParcel(Location.java:713)
04-06 21:19:38.947: ERROR/Bundle(2348): at android.location.Location$1.createFromParcel(Location.java:717)
04-06 21:19:38.947: ERROR/Bundle(2348): at com.john.scratchpad.test.BitmapClassTest.testCreator(BitmapClassTest.java:31)
04-06 21:19:38.947: ERROR/Bundle(2348): at java.lang.reflect.Method.invokeNative(Native Method)
04-06 21:19:38.947: ERROR/Bundle(2348): at java.lang.reflect.Method.invoke(Method.java:521)
04-06 21:19:38.947: ERROR/Bundle(2348): at junit.framework.TestCase.runTest(TestCase.java:154)
04-06 21:19:38.947: ERROR/Bundle(2348): at junit.framework.TestCase.runBare(TestCase.java:127)
04-06 21:19:38.947: ERROR/Bundle(2348): at junit.framework.TestResult$1.protect(TestResult.java:106)
04-06 21:19:38.947: ERROR/Bundle(2348): at junit.framework.TestResult.runProtected(TestResult.java:124)
04-06 21:19:38.947: ERROR/Bundle(2348): at junit.framework.TestResult.run(TestResult.java:109)
04-06 21:19:38.947: ERROR/Bundle(2348): at junit.framework.TestCase.run(TestCase.java:118)
04-06 21:19:38.947: ERROR/Bundle(2348): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:164)
04-06 21:19:38.947: ERROR/Bundle(2348): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:151)
04-06 21:19:38.947: ERROR/Bundle(2348): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:418)
04-06 21:19:38.947: ERROR/Bundle(2348): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1520)


But I don't understand what I'm missing!!!
chippie2000
Junior Developer
Junior Developer
 
Posts: 22
Joined: Wed Oct 07, 2009 4:11 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests