In two situations, only one of them gives me this unique error. I pretty much followed the Android Tutorial character for character, and for some reason it only works in certain areas.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, getSharedNutritionText(mMultiSelector.getSelectedPositions()));
shareIntent.setType("text/plain");
startActivity(shareIntent);
Gives the following error:
12-13 02:10:07.838 8261-8261/com.example E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.skylan.homeworkpro, PID: 8261
java.lang.RuntimeException: Parcel: unable to marshal value com.example.NutritionInfo@2d54b4d1
at android.os.Parcel.writeValue(Parcel.java:1343)
at android.os.Parcel.writeList(Parcel.java:717)
at android.os.Parcel.writeValue(Parcel.java:1290)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:644)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1034)
at android.os.Parcel.writeBundle(Parcel.java:669)
at android.app.FragmentState.writeToParcel(Fragment.java:138)
at android.os.Parcel.writeTypedArray(Parcel.java:1197)
at android.app.FragmentManagerState.writeToParcel(FragmentManager.java:376)
at android.os.Parcel.writeParcelable(Parcel.java:1363)
at android.os.Parcel.writeValue(Parcel.java:1268)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:644)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1034)
at android.os.Parcel.writeBundle(Parcel.java:669)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2925)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3299)
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: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)
Whereas in another one of my (almost) identical fragments, I have the following code:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, getSharedLabelText(mMultiSelector.getSelectedPositions()));
shareIntent.setType("text/plain");
startActivity(shareIntent);
Here's my NutritionInfo Class
public class NutritionInfo extends SugarRecord<NutritionInfo> {
public String nutritionName;
public String nutritionHeaderTitle;
public int nutritionCalories;
public boolean nutritionArchived;
public boolean nutritionChecked;
public NutritionInfo () {}
public NutritionInfo (String name, String headerTitle, int cal, boolean isArchived, boolean isChecked) {
nutritionName = name;
nutritionHeaderTitle = headerTitle;
nutritionCalories = cal;
nutritionArchived = isArchived;
nutritionChecked = isChecked;
}
}
Here's my Nutrition getter:
public class NutritionDisplayFragment extends BaseFragment implements ActionMode.Callback {
private String getSharedNutritionText(List<Integer> positions) {
String shareText;
if (positions.equals(null)) {
shareText = "";
} else {
shareText = "Food and carbs:\n";
for (int go = 0; go < positions.size(); go++) {
shareText = shareText +
nutritionList.get(go).nutritionTitle + " - \t" +
nutritionList.get(go).nutritionCarbs + "\n";
}
}
return shareText;
} ( . . . )
}
vs my Label getter:
public class LabelManagerFragment extends BaseFragment implements ActionMode.Callback {
private String getSharedLabelText(List<Integer> positions) {
String shareText = "";
if (positions.equals(null)) {
shareText = "";
} else {
for (int go = 0; go < positions.size(); go++) {
shareText = shareText +
labelList.get(go).labelName + "\t" +
labelList.get(go).labelYear + "\n";
}
}
return shareText;
} ( . . . )
}
And this gives no runtime error. Both get() methods return a simple string. Why does the first error complain about "com.package.NutritionInfo@84055e1", which isn't even the type of data being shared, as un-marshal-able and the other shares the string without a hitch?
For further clarity: I tried hardcoding "hello world"
in for where the method is (the method that usually returns a simple String
), and had the same issue.