Linkstore doesn't have a no-arg constructor does it? If so, then selectedTags
could be null. You could change its declaration to
@Persistent(defaultFetchGroup = "true")
private Set<Key> selectedTags = new HashSet<Key>(0);
I've always initialized my Collections at the declaration.
Just for experimentation, try changing its declaration to that and see what
happens.
WATCH OUT THOUGH: if you you're using eclipse you may have it configured to add
a final to fields and variables that are set when they're declared and not
subsequently written to. If that happens then DataNucleus ignores final
fields. (I wish I could change some setting to have DN throw an exception in
that situation.)
dataStorm wrote:
> 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
-~----------~----~----~----~------~----~------~--~---