• 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
NullPointerException
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NullPointerException


  • Subject: NullPointerException
  • From: Kevin Spake <email@hidden>
  • Date: Sun, 04 Dec 2011 00:01:56 -0800

Still working on the WebObjects, WOlips and Wonder tutorial, part 2...

Getting a null pointer exception. I've spent hours trying to figure out the issue, but I just don't have the experience to properly trouble shoot it. The stack trace is below, and below that is the code for my DirectAction.  The console says the error occurs on line 55, which is "if (errorMessage != null || errorMessage.length() != 0) { "

The thing is, errorMessage is null at this point. I've entered in valid user credentials, the session object has been created. The currentUser and nextPage objects are not null.  nextPage is set to "AdminPage".   As soon as I try to step into the "if (errorMessage != null || errorMessage.length() != 0) {"    line the exception occurs.  Is this a scope issue? 

Thanks.


Application: SooperSeekrit Error: java.lang.NullPointerException Reason: Stack trace:
File Line# Method Package

DirectAction.java 55 loginAction com.sooperseekrit.app
NativeMethodAccessorImpl.java NA invoke0 sun.reflect
NativeMethodAccessorImpl.java 39 invoke sun.reflect
DelegatingMethodAccessorImpl.java 25 invoke sun.reflect
Method.java 597 invoke java.lang.reflect
WODirectAction.java 144 performActionNamed com.webobjects.appserver
ERXDirectAction.java 401 performActionNamed er.extensions.appserver
WOActionRequestHandler.java 259 _handleRequest com.webobjects.appserver._private
WOActionRequestHandler.java 158 handleRequest com.webobjects.appserver._private
ERXDirectActionRequestHandler.java 126 handleRequest er.extensions.appserver
WOApplication.java 1687 dispatchRequest com.webobjects.appserver
ERXApplication.java 2021 dispatchRequestImmediately er.extensions.appserver
ERXApplication.java 1986 dispatchRequest er.extensions.appserver
WOWorkerThread.java 144 runOnce com.webobjects.appserver._private
WOWorkerThread.java 226 run com.webobjects.appserver._private
Thread.java 680 run java.lang






package com.sooperseekrit.app;

import java.util.NoSuchElementException;

import com.webobjects.appserver.WOActionResults;
import com.webobjects.appserver.WOComponent;
import com.webobjects.appserver.WORequest;
import com.webobjects.eocontrol.EOQualifier;

import er.extensions.appserver.ERXDirectAction;
import er.extensions.eof.ERXEC;

import com.sooperseekrit.components.AdminPage;
import com.sooperseekrit.components.Main;
import com.sooperseekrit.components.UserPage;
import com.sooperseekrit.model.User;

public class DirectAction extends ERXDirectAction {
public DirectAction(WORequest request) {
super(request);
}
@Override
public WOActionResults defaultAction() {
return pageWithName(Main.class.getName());
}
public WOActionResults loginAction() {
WOComponent nextPage = null;
String username = request().stringFormValueForKey("username");
String password = request().stringFormValueForKey("password");
String errorMessage = null;
if (username == null || username.length() == 0 || 
password == null || password.length() == 0) {
errorMessage = "Please enter a username and password";
} else {
try {
EOQualifier qual = User.USERNAME.eq(username).and(User.PASSWORD.eq(password));
User user = User.fetchRequiredUser(ERXEC.newEditingContext(), qual);
((Session)session()).set_currentUser(user);
if (user.group().name().equals("Admin")) {
nextPage = pageWithName(AdminPage.class.getName());
} else if (user.group().name().equals("User")) {
nextPage = pageWithName(UserPage.class.getName());
}
} catch (NoSuchElementException e) {
errorMessage = "No user found for those credentials";
} catch (Exception e) {
// something bad happened
}
}
if (errorMessage != null || errorMessage.length() != 0) {
nextPage = pageWithName(Main.class.getName());
nextPage.takeValueForKey(errorMessage, "errorMessage");
nextPage.takeValueForKey(username, "username");
nextPage.takeValueForKey(password, "password");
}
return nextPage;
}
}

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NullPointerException
      • From: Philippe Rabier <email@hidden>
  • Prev by Date: Re: Best way to remove a component?
  • Next by Date: Re: NullPointerException
  • Previous by thread: Developer in Germany
  • Next by thread: Re: NullPointerException
  • Index(es):
    • Date
    • Thread