• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Help debugging nullPtrException
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help debugging nullPtrException


  • Subject: Help debugging nullPtrException
  • From: MacFirst <email@hidden>
  • Date: Mon, 10 Nov 2003 13:04:14 -0800

I'd swear I've done this a bazillion times, but now I can't seem to figure
out why I'm getting NullPointerException on this one insertion.  In the code
(below), I saveChanges() to make sure that everything's good to that point,
then I add a simple record that's really just relationships to link 2 other
records, and I get NPE on the saveChanges() that follows the insertion.

I've added a battle record (before the code snippet, below), already.

I already have all the terrains (they were read in, earlier, on the same
EOEC.)

The problem comes when I create a new BattleTerrain -- which is just a
relationship to link a color to a battle and a terrain: i.e., "for this
battle, color 0x000090 means water".  The model looks something like this:

    A   battleTerrainID     Integer     Primary Key
    A   color               Integer
    A   flags               Integer     // unused
    A   terrainID           Integer     // used by relationship
    A   battleID            Integer     //  "    "    "

    R   terrain             to-one      terrainID -> terrainID
    R   battle              to-one      battleID -> battleID

I insert the new battleTerrain, set the color, set the battle relationship,
and set the terrain relationship.  Then, when I save changes, and it gives
NullPointerException Error (below.)

AFAICT, there's nothing wrong with my model.  The relationships are supposed
to be "mandatory", but I made them "optional", because I thought I
remembered there being some problem adding new records with mandatory
relationships.  It shouldn't matter; I add the relationships when I'm
supposed to, anyway.

Anyway... Does anything about this jump out at you guys as obviously wrong?
I've been totally stuck on this for almost a week.  :\  Any suggestions for
how to further debug it?  What sorts of things to look for, etc?

Thanks!

        --- The Code ---

    editingContext.lock();
    {
        editingContext.saveChanges();

            // set up terrains
        for (Enumeration enum = terrainHash.keys() ; enum.hasMoreElements()
; )
        {
            Integer            color        = (Integer) enum.nextElement();
            WarTerrain        terrain        = (WarTerrain) terrainHash.get
(color);
            BattleTerrain    bTerrain    = (BattleTerrain)
EOUtilities.createAndInsertInstance (editingContext, "BattleTerrain");

            bTerrain.setColor (color);
            bTerrain.setFlags (new Integer (0));
            bTerrain.addObjectToBothSidesOfRelationshipWithKey (battle,
"battle");
            bTerrain.addObjectToBothSidesOfRelationshipWithKey (terrain,
"terrain");

System.out.println ("insertedObjects: " + editingContext.insertedObjects());
            editingContext.saveChanges();       // line 178 -- the error
        }

//      editingContext.saveChanges();
    }
    editingContext.unlock();

        --- Ouput/Exception ---

insertedObjects: ({values = {battle = "<War.Battle 105002
_EOIntegralKeyGlobalID[Battle (java.lang.Integer)1000005]>"; color =
-11041869; terrain = "<War.WarTerrain 2ce9e6
_EOIntegralKeyGlobalID[WarTerrain (java.lang.Integer)1000005]>"; flags = 0;
}; this = "<War.BattleTerrain ac2837 <EOTemporaryGlobalID: 0 0 10 0 1 3 0 0
7 -38 63 0 0 0 0 -8 -65 2 -123 86 14 7 65 -88>>"; })
java.lang.NullPointerException
    at
com.webobjects.eocontrol.EOEditingContext.faultForGlobalID(EOEditingContext.
java:2914)
    at
com.webobjects.eocontrol.EOEditingContext.initializeObject(EOEditingContext.
java:3116)
    at
com.webobjects.eocontrol.EOEditingContext.saveChangesInEditingContext(EOEdit
ingContext.java:3447)
    at
com.webobjects.eocontrol.EOEditingContext.saveChanges(EOEditingContext.java:
2498)
    at BattleServer.InitIntoDB(BattleServer.java:376)
    at WarServerThread.InitBattleFromWOPage(WarServerThread.java:178)
    at BattlePage.CreateNewBattleAction(BattlePage.java:209)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        [etc., deep into reflection stuff.]

[demime 0.98b removed an attachment of type application/x-stuffit which had a name of MFWar.eomodeld.sit"; x-mac-creator="53495421"; x-mac-type="53495435]
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Help debugging nullPtrException -- SOLUTION
      • From: MacFirst <email@hidden>
  • Prev by Date: Re: Web Services Assistant
  • Next by Date: FW: Application Clustering
  • Previous by thread: Re: Web Services Assistant
  • Next by thread: Re: Help debugging nullPtrException -- SOLUTION
  • Index(es):
    • Date
    • Thread