Hello, can someone help me with this, I am trying to follow this post
http://code.google.com/appengine/docs/java/datastore/relationships.html
to
create relationship between LINKS and TAGS.

I am getting an error:

Caused by:

java.lang.NullPointerException
        at com.linkytty.Linkstore.addNewTag(Linkstore.java:101)
        at com.linkytty.TagLinker.doPost(TagLinker.java:52)


This happens when I try to add a key using ".add()"  :

public void addNewTag(Key tagKey) {

selectedTags.add(tagKey);

}


addNewTag() is called from my

PersistenceManager pm = PMF.get().getPersistenceManager();
Linkstore linkObject = pm.getObjectById(Linkstore.class, objectKey);
linkObject.addNewTag(objectKey);

I've logged my "objectKey" and etc. and it seems that it gets those
right
(
String linkKeyId = req.getParameter("key");
linkKeyID : aghsaW5reXR0eXIPCxIJTGlua3N0b3JlGAUM

Key objectKey = KeyFactory.stringToKey(linkKeyId);
objectKey: Linkstore(5)
)

My Classes:

the class that creates links:


public class Linkstore {

        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key linkid;

        @Persistent(defaultFetchGroup = "true")
        private Set<Key> selectedTags;


//STUFF HERE

        public Linkstore(User author, String linkcontent, String linkcomment,
Date
date) {
                this.author = author;
                this.linkcontent = linkcontent;
                this.linkcomment = linkcomment;

                this.date = date;

                selectedTags = new HashSet<Key>();

        }

        public Key getId() {

                return linkid;

        }

        public String getKeyAsString() {
                if (linkid == null)
                        return null;
                return KeyFactory.keyToString(linkid);
        }

        // STUFF HERE


        public void addNewTag(Key tagKey) {

                        selectedTags.add(tagKey);

        }

}

The class that captures the post:


        public void doPost(HttpServletRequest req, HttpServletResponse resp)
                        throws IOException {

                String linkKeyId = req.getParameter("key");
                Key objectKey = KeyFactory.stringToKey(linkKeyId);

                String tagStringKey = req.getParameter("tagkey");
                Key tagObjectKey = KeyFactory.stringToKey(tagStringKey);

                PersistenceManager pm = PMF.get().getPersistenceManager();
                Linkstore linkObject = pm.getObjectById(Linkstore.class, 
objectKey);

                linkObject.addNewTag(objectKey);

                resp.sendRedirect("/");
        }


///
Does the "@Persistent(defaultFetchGroup = "true")" make any
difference?


Help & Thanks!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to