I was pretty sure it was something I was doing. Yes, I just did a copy and paste.
Thanks again. Sent from my iPhone On Dec 4, 2011, at 2:48 AM, Paul D Yu <p...@mac.com> wrote: > Kevin > > This is a java or may be even programming issue, NOT a WebObjects one. > > Because of the || or operator, the runtime has to evaluate the second portion > of the condition. Since errorMessage is null, length() of errorMessage will > throw the exception... > > Paul > > Sent from my iPad > > On Dec 4, 2011, at 3:22 AM, Philippe Rabier <prab...@me.com> wrote: > >> Hi Kevin >> >> You have to use a && operator when you test if your string is not null and >> length > 0. ;-) >> >> Bad copy/paste I guess. >> >> Your code is clean. >> >> Philippe >> >> Sent from my iPhone >> >> On 4 déc. 2011, at 09:01, Kevin Spake <sparky0...@yahoo.com> wrote: >> >>> 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 (Webobjects-dev@lists.apple.com) >>> Help/Unsubscribe/Update your Subscription: >>> http://lists.apple.com/mailman/options/webobjects-dev/prabier%40me.com >>> >>> This email sent to prab...@me.com >> _______________________________________________ >> Do not post admin requests to the list. They will be ignored. >> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/webobjects-dev/pyu%40mac.com >> >> This email sent to p...@mac.com
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com