Note that there are some explanatory texts on larger screens.

plurals
  1. POPossible problems moving classes between activities
    text
    copied!<p>I am going to try to be as specific as I can. I created custom object classes that are being populated an xml file. the classes are for robots and the robots have weapons and armor etc. I am storing each iteration of the robots in an arraylist. I am then populating a list view(custom list adapter) with the information about the robot. when you click on the different parts of the robot it displays what weapons armor etc are attached to those components. This all worked fine and somehow randomly things just stopped working. its almost like the app is losing data when being passed between activities or the GC is removing some data. I have been pulling my hair out trying to figure out why all of the sudden its showing the wrong data or the data is missing. I really wish I could post the code here but its really my whole app that is now having this issue. My question i guess is. Am I storing the custom objects properly in an array list. or is their a different method. I don't even know where to start debugging this because it used to work.</p> <pre><code>private Mech loadMDF(Mech mech) { MechComponents mechComponents = null; String mechfile = ""; String name = ""; float HP = 0; int maxSlots = 0; try { XmlPullParserFactory factory; factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser(); // FileInputStream fis = new FileInputStream(file); // set the input for the parser using an InputStreamReader // xpp.setInput(new InputStreamReader(fis)); xpp.setInput(getResources().getAssets().open(mech.mdf), null); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_DOCUMENT) { } else if (eventType == XmlPullParser.START_TAG) { if (xpp.getName().equals("MechDefinition")) { for (int i = 0; i &lt; xpp.getAttributeCount(); i++) { if (xpp.getAttributeName(i).equals("HardpointPath")) { boolean found = false; String[] theFilename = xpp.getAttributeValue(i) .split("/"); for (int n = 0; n &lt; MechHardPointFiles.size(); n++) { if (MechHardPointFiles.get(n).equals( theFilename[theFilename.length - 1])) { found = true; } } if (!found) { MechHardPointFiles .add(theFilename[theFilename.length - 1]); loadMechFile(theFilename[theFilename.length - 1]); } mechfile = theFilename[theFilename.length - 1]; } } } if (xpp.getName().equals("Mech")) { for (int i = 0; i &lt; xpp.getAttributeCount(); i++) { if (xpp.getAttributeName(i).equals("MaxTons")) { mech.MaxTons = Float.parseFloat(xpp.getAttributeValue(i)); } if (xpp.getAttributeName(i).equals("BaseTons")) { mech.BaseTons = Float .parseFloat(xpp.getAttributeValue(i)); } if (xpp.getAttributeName(i).equals("CanEquipECM")) { mech.setCanEquipECM(xpp.getAttributeValue(i)); } if (xpp.getAttributeName(i).equals("MaxJumpJets")) { mech.MaxJumpJets = xpp.getAttributeValue(i); } if (xpp.getAttributeName(i).equals("LeftArmAim")) { // mech.MaxTons = // Float.parseFloat(xpp.getAttributeValue(i)); } if (xpp.getAttributeName(i).equals("RightArmAim")) { // mech.MaxTons = // Float.parseFloat(xpp.getAttributeValue(i)); } if (xpp.getAttributeName(i).equals("MinEngineRating")) { mech.MinEngineRating = Integer.parseInt(xpp .getAttributeValue(i)); } if (xpp.getAttributeName(i).equals("MaxEngineRating")) { mech.MaxEngineRating = Integer.parseInt(xpp .getAttributeValue(i)); } if (xpp.getAttributeName(i).equals("MaxJumpJets")) { mech.setCanEquipECM(xpp.getAttributeValue(i)); } } } if (xpp.getName().equals("Component")) { mechComponents = new MechComponents(); for (int i = 0; i &lt; xpp.getAttributeCount(); i++) { if (xpp.getAttributeName(i).equals("Name")) { name = helperObjects.checkForSpace(xpp .getAttributeValue(i)); } if (xpp.getAttributeName(i).equals("HP")) { HP = Float.parseFloat(xpp.getAttributeValue(i)); } if (xpp.getAttributeName(i).equals("Slots")) { maxSlots = Integer.parseInt(xpp.getAttributeValue(i)); } } } if (xpp.getName().equals("Internal")) { for (int i = 0; i &lt; xpp.getAttributeCount(); i++) { if (xpp.getAttributeName(i).equals("Name")) { mechComponents.addToSlot(xpp.getAttributeValue(i)); } } } if (xpp.getName().equals("Hardpoint")) { int hpType = 0; int hpSlots = 0; for (int i = 0; i &lt; xpp.getAttributeCount(); i++) { if (xpp.getAttributeName(i).equals("Type")) { hpType = Integer.parseInt(xpp.getAttributeValue(i)); } if (xpp.getAttributeName(i).equals("ID")) { for (int f = 0; f &lt; MechHardPoints.size(); f++) { if (MechHardPoints.get(f).hpFile.equals(mechfile)) { if (MechHardPoints.get(f).id == Integer .parseInt(xpp.getAttributeValue(i))) { hpSlots = MechHardPoints.get(f).Slots; break; } } } } } mechComponents.addHardPointRestriction(new HardPointRestriction( hpType, hpSlots)); } } else if (eventType == XmlPullParser.END_TAG) { if (xpp.getName().equals("Component")) { mechComponents.name = name; mechComponents.HP = HP; mechComponents.maxSlots = maxSlots; mech.components.add(mechComponents); Log.i("mwo_app", "Hard Point Check: " + Integer.toString(mechComponents .getHardPointRestrictions().size())); } } else if (eventType == XmlPullParser.TEXT) { } eventType = xpp.next(); } } catch (XmlPullParserException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return mech; } </code></pre> <p>This is another snippet I use to switch Activities</p> <pre><code>inte = new Intent(MainActivity2.this, MechView.class); Bundle b = new Bundle(); b.putSerializable("com.typhonpacific.mwoapp.mech", mechListAdapter.getItem(arg2)); inte.putExtras(b); startActivity(inte); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload