Robert Simoes Robert Simoes - 1 year ago 105
Android Question

Integer putExtra() in Intent Data is being set as ParcelledData causing AsyncTask exception?

I am running into an error when attempting to getExtras() from an intent. At the moment the Intent Data says its a ParcelledData piece but the argument I entered in the putExtra() method was actually of type int. This causes an exception when during the doIntBackground() process.

Application Context is a container for items called flowElements (aka. Tasks).

A Flow object has a LinkedList which keeps track of all its flowElements. is an activity where the user can see all the current flowElements in the Flow they are currently working on, or create a flowElement one. is an activity where the user can name and time their new flowElement.


//// Not expecting a parcel, expecting an integer ////
D/nhacks16.flow.Main.ElementDesigner: intent data is: Bundle[mParcelledData.dataSize=24]
D/nhacks16.flow D/nhacks16.flow.Main.ElementDesigner: Element's name is Task 1
D/nhacks16.flow D/nhacks16.flow.Main.ElementDesigner: Element's time is 20
D/nhacks16.flow D/nhacks16.flow.Main.ElementDesigner: Element's time is minutes
D/nhacks16.flow E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1

Process: nhacks16.flow, PID: 21352
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(
at java.util.concurrent.FutureTask.finishCompletion(
at java.util.concurrent.FutureTask.setException(
at android.os.AsyncTask$SerialExecutor$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$
Caused by: java.lang.NumberFormatException: Invalid int: "Bundle[mParcelledData.dataSize=24]"
at java.lang.Integer.invalidInt(
at java.lang.Integer.parse(
at java.lang.Integer.parseInt(
at java.lang.Integer.parseInt(
at nhacks16.flow.Main.ElementDesigner$newElemAsync.doInBackground(
at nhacks16.flow.Main.ElementDesigner$newElemAsync.doInBackground(
at android.os.AsyncTask$

public class SandBoxMain extends AppCompatActivity {
// The SandBox serves as a hub for a Flow Object. SandBox will:
// 1) Execute the elementDesigner activity
// 2) Draw the flowElements on its view

private static final String TAG = SandBoxMain.class.getName();
private Toolbar sbToolbar;
private Flow workingFlow;
// Flow currently being worked on
private FlowElement f;
// Global FlowElement holder

protected void onCreate(Bundle savedInstanceState) {

workingFlow = getIntent().getParcelableExtra("selectedFlow");
//This parcelable extra comes from a previous activity,
//it is a Flow object, which was selected from a ListView



public void newElement(View view) {
//Instantiate a Blank Flow Element
// Add it in the Flow's LinkedList
// Get an id to pass to element designer.
f = new FlowElement();
Log.d(TAG, "The number of Flow Elements in the current Flow is:"
+ workingFlow.getElementCount());

Log.d(TAG, "The the new blank element's Id is: "
+ f.getId());

Intent in = new Intent(SandBoxMain.this, ElementDesigner.class);

//\\~~~~~~ TROUBLE AREA ~~~~~~~//\\
in.putExtra("id", f.getId());
//Passes the element's id (position in the LinkedList) to the
//Element Designer
\\// ~~~~~~~~~~~~~~~~~~~~~~~~~ \\//

startActivityForResult(in, 1);
//Starts new activity waiting for the return data

protected void onActivityResult(int requestCode,
int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

public class ElementDesigner extends AppCompatActivity {
// This class is the activity for the flow element designer, where the
// User can name and time the new task element
// This class will create the object and assign it the inputted properties,
// Then pass them back to the SandboxMain to draw and store

private static final String TAG = ElementDesigner.class.getName();

public void saveElement(View view) {
EditText nameInput = (EditText)findViewById(;
EditText timeInput = (EditText)findViewById(;
String elementName = nameInput.getText().toString();
String elementTime = timeInput.getText().toString();
String timeUnits = selectTime.getSelectedItem().toString();

//\\ ~~~~~~ TROUBLE AREA ~~~~~~~ //\\
String elementId = getIntent().getExtras().toString();
Log.d(TAG, "intent data is: " + elementId);
\\// ~~~~~~~~~~~~~~~~~~~~~~~~~ \\//

try {
new newElemAsync().execute(elementName, elementTime,
timeUnits, elementId);

} catch (Exception e) {
Log.e(TAG, e.getMessage());

//Runs Async task to create a new FlowElement Object using user's inputs
private class newElemAsync extends AsyncTask<String, String,
FlowElement> {
protected FlowElement doInBackground(String... params) {

String elementName = params[0];
Log.d(TAG, "Element's name is " + params[0]);

Double elementTime = Double.parseDouble(params[1]);
Log.d(TAG, "Element's time is " + params[1]);

String timeUnits = params[2];
Log.d(TAG, "Element's time is " + params[2]);

//\\ ~~~~~~~~ TROUBLE AREA ~~~~~~~~ //\\
int elementId = Integer.parseInt(params[3]);
Log.d(TAG, "Element's id is " + params[3]);
\\// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\//

FlowElement newElement = new FlowElement(elementName, elementTime, timeUnits, elementId);

return newElement;

protected void onPostExecute(FlowElement newElem) {
Intent returnData = new Intent();
returnData.putExtra("newElement", newElem);

public class Flow implements Parcelable{
private static final String TAG = Flow.class.getName();
private String name;
private List<FlowElement> childFlowElements = new

public int findElement(FlowElement element) {
Log.d(TAG, "The element was found at index: " +
childFlowElements.indexOf(element) +
" in the Flow's childFlowElements LinkedList");

return childFlowElements.indexOf(element);

public void addElement(FlowElement newElement) {

edit; please note I removed the OnCreate Methods, for the sake post length!

Answer Source
 Invalid int: "Bundle[mParcelledData.dataSize=24]"

is the returned value of Bundle.toString(); which is, indeed, not a valid int. It means that in your code, you have


E.g. could be the returned value of getIntent().getExtras();


You can think of the Bundle as a key-value map. So if you are adding a value using one of its put (putInt) method, you have to use one of its get (getInt) method to retrieve it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download