You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by robnangle <ro...@gmail.com> on 2011/04/08 13:59:48 UTC

Object creator set to null..

I am working on my index page and I am setting the side bars based on three
types of people that will be on it:
1) A normal user who userType is null, as they will never have the option to
view or change it
2)An admin user who userType is set to a string "Admin"
3) Any viewer who will be able to see basic information..  

However i am getting a line not available error, saying there is a null
pointer on the object? 

Code:

public boolean adminUser() {
		/*if(!user.getUserType().equalsIgnoreCase("Admin")) {
				adminUser = false;
			}
			else*/ if(user.getUserType().equalsIgnoreCase("Admin")) {
				adminUser = true;
				setAdminUser(true);
			}
		return adminUser;
	}	

	public boolean getAdminUser() {
		return adminUser;
	}

	public void setAdminUser(boolean adminUser) {
		this.adminUser = adminUser;
	}

	public Object onSubmitFromLogin() throws Exception {
		createDb();		
		if (validUser()) {
			adminUser();
			return index;			
		}
		else {
			login.recordError("Invalid Login");
			return loginPage;
		}
	}

In the tml i just use the  statements to determine between the different
types..

Any ideas as how to get around this?


--
View this message in context: http://tapestry.1045711.n5.nabble.com/Object-creator-set-to-null-tp4290653p4290653.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Object creator set to null..

Posted by Rich M <ri...@moremagic.com>.
For trivia it's worth noting that the String equals and equalsIgnoreCase 
methods also return false on null inputs, so you can also write:

if("Admin".equalsIgnoreCase( user.getUserType() )) {
  ...
}


On 04/08/2011 08:51 AM, robnangle wrote:
> Richard Hill-7 wrote:
>> Well you can't call a method on null! null is not a String with value
>> "null". It's a special value in java - basically a reference to a value
>> called null (i.e distinct from an undefined variable that has no
>> reference assigned). You need to check for a null value before calling
>> any methods:
>>
>> if(user.getUserType() != null&&
>> user.getUserType().equalsIgnoreCase("Admin")) {
>>
>> ....
>>
>>
>>
>>
>> On Fri, 2011-04-08 at 05:38 -0700, robnangle wrote:
>>> Richard Hill-7 wrote:
>>>> You don't say what line your getting your npe but I'm guessing it's
>>>> this:
>>>>
>>>> if(user.getUserType().equalsIgnoreCase("Admin")
>>>>
>>>> if .getUserType() is null as you imply it can be then
>>>> calling .equalsIgnorecase() is going to result in an npe.
>>>>
>>> Ye thats the line im getting it on. Yes everybodys userType will be null
>>> after the first user who was set to Admin. How do I get around this or is
>>> it
>>> possible?
>>>
>>> I thought you could just:
>>>
>>> public boolean adminUser() {
>>> 		if(user.getUserType().equalsIgnoreCase("Admin")) {
>>> 				adminUser = true;
>>> 				setAdminUser(true);
>>> 			}
>>> 			else if(user.getUserType().equalsIgnoreCase(null)) {
>>> 				adminUser = false;				
>>> 			}
>>> 		return adminUser;
>>> 	}	
>>>
>>> However it never goes by the first if when the user is not an admin
>>> user..
>>>
>>>
>>> --
>>> View this message in context:
>>> http://tapestry.1045711.n5.nabble.com/Object-creator-set-to-null-tp4290653p4290718.html
>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
> Of course.. Cheers
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Object-creator-set-to-null-tp4290653p4290738.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Object creator set to null..

Posted by robnangle <ro...@gmail.com>.
Richard Hill-7 wrote:
> 
> Well you can't call a method on null! null is not a String with value
> "null". It's a special value in java - basically a reference to a value
> called null (i.e distinct from an undefined variable that has no
> reference assigned). You need to check for a null value before calling
> any methods:
> 
> if(user.getUserType() != null &&
> user.getUserType().equalsIgnoreCase("Admin")) { 
> 
> ....
> 
> 
> 
> 
> On Fri, 2011-04-08 at 05:38 -0700, robnangle wrote:
>> Richard Hill-7 wrote:
>> > 
>> > You don't say what line your getting your npe but I'm guessing it's
>> > this:
>> > 
>> > if(user.getUserType().equalsIgnoreCase("Admin")
>> > 
>> > if .getUserType() is null as you imply it can be then
>> > calling .equalsIgnorecase() is going to result in an npe.
>> > 
>> 
>> Ye thats the line im getting it on. Yes everybodys userType will be null
>> after the first user who was set to Admin. How do I get around this or is
>> it
>> possible?
>> 
>> I thought you could just:
>> 
>> public boolean adminUser() {
>> 		if(user.getUserType().equalsIgnoreCase("Admin")) {
>> 				adminUser = true;
>> 				setAdminUser(true);
>> 			}
>> 			else if(user.getUserType().equalsIgnoreCase(null)) {
>> 				adminUser = false;				
>> 			}
>> 		return adminUser;
>> 	}	
>> 
>> However it never goes by the first if when the user is not an admin
>> user..
>> 
>> 
>> --
>> View this message in context:
>> http://tapestry.1045711.n5.nabble.com/Object-creator-set-to-null-tp4290653p4290718.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

Of course.. Cheers

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Object-creator-set-to-null-tp4290653p4290738.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Object creator set to null..

Posted by Richard Hill <ri...@su3analytics.com>.
sorry: s/undefined/uninitialised


On Fri, 2011-04-08 at 13:47 +0100, Richard Hill wrote:
> Well you can't call a method on null! null is not a String with value
> "null". It's a special value in java - basically a reference to a value
> called null (i.e distinct from an undefined variable that has no
> reference assigned). You need to check for a null value before calling
> any methods:
> 
> if(user.getUserType() != null &&
> user.getUserType().equalsIgnoreCase("Admin")) { 
> 
> ....
> 
> 
> 
> 
> On Fri, 2011-04-08 at 05:38 -0700, robnangle wrote:
> > Richard Hill-7 wrote:
> > > 
> > > You don't say what line your getting your npe but I'm guessing it's
> > > this:
> > > 
> > > if(user.getUserType().equalsIgnoreCase("Admin")
> > > 
> > > if .getUserType() is null as you imply it can be then
> > > calling .equalsIgnorecase() is going to result in an npe.
> > > 
> > 
> > Ye thats the line im getting it on. Yes everybodys userType will be null
> > after the first user who was set to Admin. How do I get around this or is it
> > possible?
> > 
> > I thought you could just:
> > 
> > public boolean adminUser() {
> > 		if(user.getUserType().equalsIgnoreCase("Admin")) {
> > 				adminUser = true;
> > 				setAdminUser(true);
> > 			}
> > 			else if(user.getUserType().equalsIgnoreCase(null)) {
> > 				adminUser = false;				
> > 			}
> > 		return adminUser;
> > 	}	
> > 
> > However it never goes by the first if when the user is not an admin user..
> > 
> > 
> > --
> > View this message in context: http://tapestry.1045711.n5.nabble.com/Object-creator-set-to-null-tp4290653p4290718.html
> > Sent from the Tapestry - User mailing list archive at Nabble.com.
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> > 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Object creator set to null..

Posted by Richard Hill <ri...@su3analytics.com>.
Well you can't call a method on null! null is not a String with value
"null". It's a special value in java - basically a reference to a value
called null (i.e distinct from an undefined variable that has no
reference assigned). You need to check for a null value before calling
any methods:

if(user.getUserType() != null &&
user.getUserType().equalsIgnoreCase("Admin")) { 

....




On Fri, 2011-04-08 at 05:38 -0700, robnangle wrote:
> Richard Hill-7 wrote:
> > 
> > You don't say what line your getting your npe but I'm guessing it's
> > this:
> > 
> > if(user.getUserType().equalsIgnoreCase("Admin")
> > 
> > if .getUserType() is null as you imply it can be then
> > calling .equalsIgnorecase() is going to result in an npe.
> > 
> 
> Ye thats the line im getting it on. Yes everybodys userType will be null
> after the first user who was set to Admin. How do I get around this or is it
> possible?
> 
> I thought you could just:
> 
> public boolean adminUser() {
> 		if(user.getUserType().equalsIgnoreCase("Admin")) {
> 				adminUser = true;
> 				setAdminUser(true);
> 			}
> 			else if(user.getUserType().equalsIgnoreCase(null)) {
> 				adminUser = false;				
> 			}
> 		return adminUser;
> 	}	
> 
> However it never goes by the first if when the user is not an admin user..
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Object-creator-set-to-null-tp4290653p4290718.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Object creator set to null..

Posted by robnangle <ro...@gmail.com>.
Richard Hill-7 wrote:
> 
> You don't say what line your getting your npe but I'm guessing it's
> this:
> 
> if(user.getUserType().equalsIgnoreCase("Admin")
> 
> if .getUserType() is null as you imply it can be then
> calling .equalsIgnorecase() is going to result in an npe.
> 

Ye thats the line im getting it on. Yes everybodys userType will be null
after the first user who was set to Admin. How do I get around this or is it
possible?

I thought you could just:

public boolean adminUser() {
		if(user.getUserType().equalsIgnoreCase("Admin")) {
				adminUser = true;
				setAdminUser(true);
			}
			else if(user.getUserType().equalsIgnoreCase(null)) {
				adminUser = false;				
			}
		return adminUser;
	}	

However it never goes by the first if when the user is not an admin user..


--
View this message in context: http://tapestry.1045711.n5.nabble.com/Object-creator-set-to-null-tp4290653p4290718.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Object creator set to null..

Posted by Richard Hill <ri...@su3analytics.com>.
You don't say what line your getting your npe but I'm guessing it's
this:

if(user.getUserType().equalsIgnoreCase("Admin")

if .getUserType() is null as you imply it can be then
calling .equalsIgnorecase() is going to result in an npe.




On Fri, 2011-04-08 at 04:59 -0700, robnangle wrote:
> I am working on my index page and I am setting the side bars based on three
> types of people that will be on it:
> 1) A normal user who userType is null, as they will never have the option to
> view or change it
> 2)An admin user who userType is set to a string "Admin"
> 3) Any viewer who will be able to see basic information..  
> 
> However i am getting a line not available error, saying there is a null
> pointer on the object? 
> 
> Code:
> 
> public boolean adminUser() {
> 		/*if(!user.getUserType().equalsIgnoreCase("Admin")) {
> 				adminUser = false;
> 			}
> 			else*/ if(user.getUserType().equalsIgnoreCase("Admin")) {
> 				adminUser = true;
> 				setAdminUser(true);
> 			}
> 		return adminUser;
> 	}	
> 
> 	public boolean getAdminUser() {
> 		return adminUser;
> 	}
> 
> 	public void setAdminUser(boolean adminUser) {
> 		this.adminUser = adminUser;
> 	}
> 
> 	public Object onSubmitFromLogin() throws Exception {
> 		createDb();		
> 		if (validUser()) {
> 			adminUser();
> 			return index;			
> 		}
> 		else {
> 			login.recordError("Invalid Login");
> 			return loginPage;
> 		}
> 	}
> 
> In the tml i just use the  statements to determine between the different
> types..
> 
> Any ideas as how to get around this?
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Object-creator-set-to-null-tp4290653p4290653.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org