Error with reading parcelable object (after application is restored) - android

I have to save my custom class in save state bundle. So, I made it Parcelable and it looks good. When I rotate screen everything is goind well. But, when I minimalize my app, open some other, rotate screen and I try to go back to my app (from recent apps) it crashes.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.game/com.example.game.MainActivity}: java.lang.RuntimeException: Parcelable encountered ClassNotFoundException reading a Serializable object (name = com.example.game.Player)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.RuntimeException: Parcelable encountered ClassNotFoundException reading a Serializable object (name = com.example.game.Player)
at android.os.Parcel.readSerializable(Parcel.java:2378)
at android.os.Parcel.readValue(Parcel.java:2197)
at android.os.Parcel.readListInternal(Parcel.java:2520)
at android.os.Parcel.readList(Parcel.java:1655)
at com.example.game.Players.<init>(Players.java:106)
at com.example.game.Players$1.createFromParcel(Players.java:96)
at com.example.game.Players$1.createFromParcel(Players.java:93)
at android.os.Parcel.readParcelable(Parcel.java:2246)
at android.os.Parcel.readValue(Parcel.java:2146)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:831)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
at android.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1864)
at android.app.Activity.onCreate(Activity.java:949)
at com.example.game.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:6020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5297)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.ClassNotFoundException: com.example.game.Player
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at android.os.Parcel$2.resolveClass(Parcel.java:2364)
at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1641)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:657)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1782)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:761)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
at android.os.Parcel.readSerializable(Parcel.java:2372)
            at android.os.Parcel.readValue(Parcel.java:2197)
            at android.os.Parcel.readListInternal(Parcel.java:2520)
            at android.os.Parcel.readList(Parcel.java:1655)
            at com.example.game.Players.<init>(Players.java:106)
            at com.example.game.Players$1.createFromParcel(Players.java:96)
            at com.example.game.Players$1.createFromParcel(Players.java:93)
            at android.os.Parcel.readParcelable(Parcel.java:2246)
            at android.os.Parcel.readValue(Parcel.java:2146)
            at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
            at android.os.BaseBundle.unparcel(BaseBundle.java:221)
            at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:831)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
            at android.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1864)
            at android.app.Activity.onCreate(Activity.java:949)
            at com.example.game.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:6020)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5297)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.ClassNotFoundException: com.example.game.Player
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:308)
            at android.os.Parcel$2.resolveClass(Parcel.java:2364)
            at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1641)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:657)
            at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1782)
            at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:761)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
            at android.os.Parcel.readSerializable(Parcel.java:2372)
            at android.os.Parcel.readValue(Parcel.java:2197)
            at android.os.Parcel.readListInternal(Parcel.java:2520)
at android.os.Parcel.readList(Parcel.java:1655)
            at com.example.game.Players.<init>(Players.java:106)
            at com.example.game.Players$1.createFromParcel(Players.java:96)
            at com.example.game.Players$1.createFromParcel(Players.java:93)
            at android.os.Parcel.readParcelable(Parcel.java:2246)
            at android.os.Parcel.readValue(Parcel.java:2146)
            at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
            at android.os.BaseBundle.unparcel(BaseBundle.java:221)
            at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:831)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
            at android.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1864)
            at android.app.Activity.onCreate(Activity.java:949)
            at com.example.game.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:6020)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5297)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
So, players is parcelable class. It is basically a List. Player is another class, serializable.
Player.java
import java.io.Serializable;
public class Player implements Serializable{
private String name;
private int points = 0;
// getters and setters
}
Players.java
public class Players implements Parcelable {
private List<Player> players;
//constructor, getters, setters
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeList(players);
}
public static final Parcelable.Creator<Players> CREATOR = new Parcelable.Creator<Players>() {
public Players createFromParcel(Parcel in) {
return new Players(in);
}
public Players[] newArray(int size) {
return new Players[size];
}
};
public Players(Parcel in) {
in.readList(players, List.class.getClassLoader());
}
}
At this point I don't know why my app crash. When I rotate it it's ok, when I minimize and maximize is ok, when I minimize, do some staff (open another app, rotate screen etc) and try to maximize it from recents it crash.
I'll be very gratefull for any kind of help ;) !
Have a good afternoon!

Parcelable class nest parcelable objects only.
Here in your case Player is not parcelable and is used in Parcelable class Players. Try to implement Parcelable in Player class too.
Your problem with minimising and opening the application is because Parcelable object is saved but it is not retrieved properly.
try to make following changes in your code :
public class Player implements Parcelable{
String name;
int points;
// getter setter
public static final Creator<Player> CREATOR = new Parcelable.Creator<Player>() {
#Override
public Player createFromParcel(Parcel in) {
return new Player(in);
}
#Override
public Player[] newArray(int size) {
return new Player[size];
}
};
public Player(Parcel in) {
this.name = in.readString();
this.points = in.readInt();
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(points);
}
}
And in Players class while reading the list replace:
in.readList(players, List.class.getClassLoader());
with :
players = new ArrayList<>();
in.readList(players, getClass().getClassLoader());
Your code should work fine after these changes.

Related

android.app.Fragment$InstantiationException: Trying to instantiate a class ScannerFragment that is not a Fragment

I updated a few libraries in app.gradle like support library from 22.2.0 -> 23.0.0 and versions of few third party libraries, and now I'm getting the following runtime error in one particular activity:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.shubhamkanodia.bookmybook/com.example.shubhamkanodia.bookmybook.AddBooksActivity_}: android.view.InflateException: Binary XML file line #155: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: android.view.InflateException: Binary XML file line #155: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.setContentView(AddBooksActivity_.java:56)
at com.example.shubhamkanodia.bookmybook.AddBooksActivity.onCreate(AddBooksActivity.java:140)
at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.onCreate(AddBooksActivity_.java:46)
at android.app.Activity.performCreate(Activity.java:6010)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
            at android.app.ActivityThread.access$800(ActivityThread.java:155)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5343)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.example.shubhamkanodia.bookmybook.Fragments.ScannerFragment that is not a Fragment
at android.app.Fragment.instantiate(Fragment.java:606)
at android.app.Fragment.instantiate(Fragment.java:582)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2110)
at android.app.Activity.onCreateView(Activity.java:5348)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.setContentView(AddBooksActivity_.java:56)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity.onCreate(AddBooksActivity.java:140)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.onCreate(AddBooksActivity_.java:46)
            at android.app.Activity.performCreate(Activity.java:6010)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
            at android.app.ActivityThread.access$800(ActivityThread.java:155)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5343)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: java.lang.ClassCastException
            at android.app.Fragment.instantiate(Fragment.java:606)
            at android.app.Fragment.instantiate(Fragment.java:582)
            at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2110)
            at android.app.Activity.onCreateView(Activity.java:5348)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.setContentView(AddBooksActivity_.java:56)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity.onCreate(AddBooksActivity.java:140)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.onCreate(AddBooksActivity_.java:46)
            at android.app.Activity.performCreate(Activity.java:6010)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
            at android.app.ActivityThread.access$800(ActivityThread.java:155)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5343)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
In particular this line seems strange:
Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.example.shubhamkanodia.bookmybook.Fragments.ScannerFragment that is not a Fragment
( ScannerFragment is a fragment that implements dm77 barcode scanner which i updated from 1.7.2 to 1.8.2 )
Scanner Fragment:
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import me.dm7.barcodescanner.zbar.BarcodeFormat;
import me.dm7.barcodescanner.zbar.Result;
import me.dm7.barcodescanner.zbar.ZBarScannerView;
public class ScannerFragment extends Fragment implements MessageDialogFragment.MessageDialogListener,
ZBarScannerView.ResultHandler, FormatSelectorDialogFragment.FormatSelectorDialogListener,
CameraSelectorDialogFragment.CameraSelectorDialogListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
mScannerView = new ZBarScannerView(getActivity());
//stuff
return mScannerView;
}
#Override
public void onActivityCreated(Bundle state){
super.onCreate(state);
//stuff
}
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
setHasOptionsMenu(true);
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
//stuff
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
//stuff
}
#Override
public void onResume() {
super.onResume();
//stuff
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//stuff
}
#Override
public void handleResult(Result rawResult) {
//stuff
}
#Override
public void onPause() {
super.onPause();
//stuff
}
XML Snippet:
<FrameLayout
android:id="#+id/flScan"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/fScanner"
class="com.example.shubhamkanodia.bookmybook.Fragments.ScannerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="8dp"
android:background="#color/transparent"
android:padding="12dp">
<ImageButton
android:id="#+id/ibAutofocus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/ripple_light"
android:clickable="true"
android:contentDescription="Enable / Disable Autofocus"
android:longClickable="true"
android:padding="8dp"
android:src="#mipmap/ic_action_auto_focus_on" />
<ImageButton
android:id="#+id/ibFlashControl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/ibAutofocus"
android:background="#drawable/ripple_light"
android:clickable="true"
android:contentDescription="Enable / Disable Flash"
android:longClickable="true"
android:padding="8dp"
android:src="#mipmap/ic_action_image_flash_off" />
</RelativeLayout>
</FrameLayout>
Any help would be appreciated!
Try importing android.app.Fragment instead of android.support.v4.app.Fragment basically don't use support library if you don't need it 'or check that Activity in which you are inflating this fragment about : Whether you are using the FragmentManager and FragmentTransaction from support library only.

Unable to start activity ComponentInfo{Activity}: android.view.InflateException: Binary XML file line Error inflating class fragment

I am getting the following exception, when I try to start a fragment inside a activity. It seems like this is a common problem, I have all the permissions necessary as suggested in the answers. The trace is not very helpful.
Process: com.eazysystems.transdoc, PID: 11129
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxx.xxxx/com.xxxx.xxxx.view.ViewRecordActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.eazysystems.transdoc.view.ViewRecordActivity.onCreate(ViewRecordActivity.java:21)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.support.v4.app.Fragment.isSupportFragmentClass(Fragment.java:455)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2135)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:838)
at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:34)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:826)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
            at com.eazysystems.transdoc.view.ViewRecordActivity.onCreate(ViewRecordActivity.java:21)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
And also, the exception happens at the setContentView(R.layout.activity_view_record); in this Activity class. I tried to make the application simple as possible but it get the same exception
public class ViewRecordActivity extends AppCompatActivity {
private static String RECORD_ID = "RECORD_ID";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_record);
/*Bundle extras = getIntent().getExtras();
Integer recordId = extras.getInt(RECORD_ID);*/
ViewRecordFragment viewRecordFragment = ViewRecordFragment.newInstance(1);
//viewRecordFragment.setArguments(getIntent().getExtras());
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager
.beginTransaction()
.replace(R.id.view_record_fragment, viewRecordFragment
).commit();
}
public static class ViewRecordFragment extends Fragment {
private static String RECORD_ID = "RECORD_ID";
public ViewRecordFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/*gridview = (GridView) getActivity().findViewById(R.id.image_grid_view);*/
//Integer recordId = getArguments().getInt(RECORD_ID);
//loadImageResourcesAsync(recordId);
return inflater.inflate(R.layout.fragment_view_record, container, false);
}
public static ViewRecordFragment newInstance(Integer recordId) {
ViewRecordFragment fragment = new ViewRecordFragment();
//fragment.loadImageResourcesAsync(recordId);
/*Bundle bundle = new Bundle();
bundle.putInt(RECORD_ID, recordId);
fragment.setArguments(bundle);*/
return fragment;
}
private void loadImageResourcesAsync(Integer recordId) {
new LoadImageResourcesAsync(getActivity()).execute(recordId);
}
}
}
layout for the activity as follows.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/view_record_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!--<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/view_record_fragment"
android:name="com.xxx.xxx.view.ViewRecordActivity$ViewRecordFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/fragment_view_record" />-->
</LinearLayout>
Any help is greatly appreciated.
Basic way of adding fragments in layout is like below. You have to mention the class name of the fragment.
<fragment android:name="com.example.android.fragments.HeadlinesFragment"
android:id="#+id/headlines_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />

OnClickListener inside the fragment gives Null Pointer Exception

I have a image button to delete that particular row inside a listview in a fragment.When I run the activity from main activity it gives NPE.
Here is the logcat output
03-10 12:29:36.647 2525-2525/com.restaurantmgmt.dcode1.restaurantms E/libprocessgroup﹕ failed to make and chown /acct/uid_10007: Read-only file system
03-10 12:29:50.351 2525-2525/com.restaurantmgmt.dcode1.restaurantms E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.restaurantmgmt.dcode1.restaurantms, PID: 2525
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.restaurantmgmt.dcode1.restaurantms/com.restaurantmgmt.dcode1.restaurantms.menu}: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.restaurantmgmt.dcode1.restaurantms.menu.onCreate(menu.java:18)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.restaurantmgmt.dcode1.restaurantms.SidePanelFragment.onCreateView(SidePanelFragment.java:45)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1045)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1147)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2116)
at android.app.Activity.onCreateView(Activity.java:5282)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.restaurantmgmt.dcode1.restaurantms.menu.onCreate(menu.java:18)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Here is the relevant code from the SidePanelActivity
public class SidePanelFragment extends android.app.Fragment implements View.OnClickListener {
ListView list1;
Items addedItems=null;
ImageButton btnDelete;
Items[] addedItms=new Items[100];
//Items[] addedItms=null;
ArrayList<Items> itemsArray=null;
ItemsAdapter1 adapter=null;
int countSideList=0;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view =inflater.inflate(R.layout.fragment_side_panel,container,false);
list1=(ListView)view.findViewById(R.id.listViewSide);
btnDelete=(ImageButton)view.findViewById(R.id.btndelete);
itemsArray= new ArrayList<Items>();
btnDelete.setOnClickListener(this);
return view;
}
#Override
public void onClick(View v) {
Toast.makeText(getActivity(),"btndelete clicked",Toast.LENGTH_LONG);
}
}
And here is the activity which has the fragment
public class menu extends ActionBarActivity implements OnAddItemPressed{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
int screenOrien=getResources().getConfiguration().orientation;
if(screenOrien== Configuration.ORIENTATION_PORTRAIT) {
hideSidePanel();
}
else
{
}
}
private void hideSidePanel() {
View side=findViewById(R.id.side_panel);
if(side.getVisibility()==View.VISIBLE)
{
side.setVisibility(View.GONE);
}
}
#Override
public void onAddItemPressed(Items item){
FragmentManager manager= getFragmentManager();
SidePanelFragment sideObj= (SidePanelFragment) manager.findFragmentById(R.id.side_panel);
sideObj.getAddedItems(item);
}
}
I have set a breakpoint at btnDelete.setOnClickListener(this);
and btnDelete is null in the debug window at that breakpoint.
Try this way :
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btndelete:
Toast.makeText(getActivity(),"btndelete clicked",Toast.LENGTH_LONG);
break;
}
Also try to replace your implements View.OnClickListener to implements OnClickListener
Make sure this btndelete id is on your fragment_side_panel.xml

Find missing onError in the project

I am trying to locate a missing onError() in a project. It means that the app crashes because a subscription does not handle the throwables so I want to locate that subcription and add the onError method.
Unfortunatelly the stacktrace is not really helpful here and it only shows the line of the throw new IOException but nothing more:
FATAL EXCEPTION: main
Process: my.app.example.dev, PID: 20309
java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:54)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError
at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)
at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)
at rx.android.app.OperatorConditionalBinding$1.onError(OperatorConditionalBinding.java:69)
at rx.internal.operators.NotificationLite.accept(NotificationLite.java:147)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:177)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access$000(OperatorObserveOn.java:65)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:153)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: rx.exceptions.CompositeException: 2 exceptions occurred.
            at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)
            at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)
            at rx.android.app.OperatorConditionalBinding$1.onError(OperatorConditionalBinding.java:69)
            at rx.internal.operators.NotificationLite.accept(NotificationLite.java:147)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:177)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access$000(OperatorObserveOn.java:65)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:153)
            at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received =>
at com.splunk.mint.ExceptionHandler.uncaughtException(ExceptionHandler.java:42)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:58)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: retrofit.RetrofitError: java.io.IOException: No connectivity
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:385)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:221)
at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:271)
at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:269)
at retrofit.RxSupport$2.run(RxSupport.java:46)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.io.IOException: No connectivity
at my.app.example.manager.ApiManager$NetworkAwareOKClient.execute(ApiManager.java:1071)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:322)
            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:221)
            at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:271)
            at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:269)
            at retrofit.RxSupport$2.run(RxSupport.java:46)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
Any ideas to locate the subscription (line in code) that does not have the onError() ?
This can be a pain to debug. Funnily enough I had an error inside the Action1<Throwable> [facepalm].
The best was to debug this is to register a global error handler. This will saw you the truth in your code:
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
#Override
public void handleError(Throwable e) {
Log.w("Error",e);
}
});
A discussion on github: https://github.com/ReactiveX/RxJava/issues/2293
If the onError is not implemented, then RxJava throw a OnErrorNotImplementedException exception. It's seems that RxJava didn't succed to call the onError method ("Error occurred when trying to propagate error to Observer.onError")
You can try to register an error handler to find the root exception.
static {
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
#Override
public void handleError(Throwable e) {
e.printStackTrace();
}
});
}
Use this one:
RxJavaHooks.setOnError(throwable -> {
if (throwable != null && throwable.getMessage() != null) {
Log.e("Error", throwable.getMessage());
}
});
Instead of deprecated RxJavaPlugins.getInstance()

Odd "Class not found when unmarshalling" error

So I encountered a strange Class not found when unmarshalling error in my app. Everytime I fire up an activity with parcelable object in the intent I get this error but everything seems to work fine. I wrote a simple app to test parcels and this error. The app has one button which launches new activity with following code:
public void onClick(View v) {
Intent i = new Intent(getActivity(), Display.class);
Data data = new Data(49, "Foobar");
i.putExtra("data", data);
startActivity(i);
}
When I tap the button I get looong error/stacktrace which you'll find in the bottom of this post. The interesting thing is that I don't even need to handle the bundle/parcel/data in the new activity to get this error. I'm starting to belive that my phone(Galaxy S3 LTE) f*cks with the parcel somehow since I haven't been able to reproduce this error with emulator or S2.
Has anyone else encountered this behaviour or have some ideas how I could try to fix this?
The parcel object I use is the following:
public class Data implements Parcelable {
private int mNumber;
private String mText;
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mNumber);
dest.writeString(mText);
}
public Data(Parcel in) {
mNumber = in.readInt();
mText = in.readString();
}
public static final Creator<Data> CREATOR = new Creator<Data>() {
#Override
public Data createFromParcel(Parcel source) {
return new Data(source);
}
#Override
public Data[] newArray(int size) {
return new Data[size];
}
};
public int getNumber() {
return mNumber;
}
public String getText() {
return mText;
}
public Data(int num, String s) {
mNumber = num;
mText = s;
}
}
and the error:
10-20 22:15:22.605 2378-2389/? E/DatabaseUtils﹕ Writing exception to parcel
java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13101)
at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
at android.os.Binder.execTransact(Binder.java:388)
at dalvik.system.NativeStart.run(Native Method)
10-20 22:15:22.610 2378-2997/? E/Parcel﹕ Class not found when unmarshalling: com.foobar.parceltest.Data
java.lang.ClassNotFoundException: com.foobar.parceltest.Data
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at java.lang.Class.forName(Class.java:169)
at android.os.Parcel.readParcelableCreator(Parcel.java:2091)
at android.os.Parcel.readParcelable(Parcel.java:2055)
at android.os.Parcel.readValue(Parcel.java:1971)
at android.os.Parcel.readMapInternal(Parcel.java:2255)
at android.os.Bundle.unparcel(Bundle.java:223)
at android.os.Bundle.getString(Bundle.java:1082)
at android.content.Intent.getStringExtra(Intent.java:4961)
at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3761)
at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:4981)
at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3163)
at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3119)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:157)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2115)
at android.os.Binder.execTransact(Binder.java:388)
at dalvik.system.NativeStart.run(Native Method)
Caused by: java.lang.NoClassDefFoundError: com/foobar/parceltest/Data
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:204)
            at java.lang.Class.forName(Class.java:169)
            at android.os.Parcel.readParcelableCreator(Parcel.java:2091)
            at android.os.Parcel.readParcelable(Parcel.java:2055)
            at android.os.Parcel.readValue(Parcel.java:1971)
            at android.os.Parcel.readMapInternal(Parcel.java:2255)
            at android.os.Bundle.unparcel(Bundle.java:223)
            at android.os.Bundle.getString(Bundle.java:1082)
            at android.content.Intent.getStringExtra(Intent.java:4961)
            at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3761)
            at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:4981)
            at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3163)
            at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3119)
            at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:157)
            at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2115)
            at android.os.Binder.execTransact(Binder.java:388)
            at dalvik.system.NativeStart.run(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.foobar.parceltest.Data" on path: .
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:204)
            at java.lang.Class.forName(Class.java:169)
            at android.os.Parcel.readParcelableCreator(Parcel.java:2091)
            at android.os.Parcel.readParcelable(Parcel.java:2055)
            at android.os.Parcel.readValue(Parcel.java:1971)
            at android.os.Parcel.readMapInternal(Parcel.java:2255)
            at android.os.Bundle.unparcel(Bundle.java:223)
            at android.os.Bundle.getString(Bundle.java:1082)
            at android.content.Intent.getStringExtra(Intent.java:4961)
            at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3761)
            at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:4981)
            at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3163)
            at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3119)
            at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:157)
            at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2115)
            at android.os.Binder.execTransact(Binder.java:388)
            at dalvik.system.NativeStart.run(Native Method)

Categories

Resources