Re: JESS: Jess Access Control

"Ernest Friedman-Hill" <[email protected]>
Newsgroups gmane.comp.java.jess
Message-ID <[email protected]>
On Jan 7, 2011, at 8:06 PM, Michael Eugene Artz wrote:
>  It's a casting error but it doesn't make any sense to me why I  
> would be getting that.

userProfiles is a java.util.Set. The method Set.add() returns boolean  
(true means the add() succeeded, false means the object was already in  
the set.) So here you're mapping Integer to Boolean.


>      profiles.put(new Integer(1), userProfiles.add(new Profile(1,  
> "Mike", "Artz")));
>      profiles.put(new Integer(2), userProfiles.add(new Profile(2,  
> "Suzy", "Kolber")));
>      profiles.put(new Integer(3), userProfiles.add(new Profile(3,  
> "Stan", "Mikita")));
>      profiles.put(new Integer(4), userProfiles.add(new Profile(4,  
> "Nikita", "Kruschev")));
>

Here you're assuming that the values in profiles are Profile objects,  
but as we said, they're Booleans.


>  public Profile getProfile(int profileNumber)
>  {
>   //return new Profile(1, "Mike", "Artz");
>   return (Profile)profiles.get(new Integer(profileNumber));
>  }
>

Which is what the error says: the values are Booleans, not Profiles.  
The trace tells you exactly what line causes the errors, so a  
println() or two would have easily told you the whole story.


> java.lang.ClassCastException: java.lang.Boolean cannot be cast to  
> Profile
> at DemoDatabase.getProfile(DemoDatabase.java:49)
> at Demo.processRole(Demo.java:31)
> at Demo.main(Demo.java:13)
>
>
> I wonder if I could this all much simpler and Im just wasting my  
> time completely:(
>


When I assemble a large program like this, I start with a small  
program that does one little thing, and I test it. I then add a little  
more, and test that, and so on. At each step, I make sure all the new  
code does what it's supposed to do. I keep all the test code so it can  
be run at any time to verify that the program still works. That way,  
you never find yourself looking at a big pile of code and wondering  
where the problem is: the problem is always just in that last little  
bit you just coded.

Good luck!


---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs
PO Box 969, MS 9012                            [email protected]
Livermore, CA 94550                             http://www.jessrules.com





--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [email protected]'
in the BODY of a message to [email protected], NOT to the list
(use your own address!) List problems? Notify [email protected].
--------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.