Results 1 to 3 of 3
- 09-15-2011, 09:14 PM #1
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
Get super class field value - Completly stuck -.-
Hi!
Im creating a building ground for experimenting with building a AI brain :)
It's quite intressting, but I got some problems.
To be easily mod newly made classes, I want a property window. So when I click a class (in my graphics screen) then it should list all values of the class and its superclass.
For example, I got the class:
So I want to create a jlabel called width, and a jtextfield next to it which has the value "0".PHP Code:class dot extends point{ int width = 0; } class point{ int height = 10; }
Then a jlabel with the text height and jtextfield with value "10".
Problem is, I have no clue what the error message meens!
Java Code:java.lang.IllegalAccessException: Class main.PropertiesWindow can not access a member of class xcomp.XComponent with modifiers ""
So far Im just trying to list the superclass fields, because the class itself has no value thats important.
The error is at this line:PHP Code:Field[] fields2 = object.getClass().getSuperclass().getDeclaredFields(); for(Field f : fields2){ Class c = f.getType(); if (c.equals(String.class) || c.equals(Integer.class) || c.equals(int.class)){ String name = f.toString(); String[] parts = name.split(" "); String part = parts[parts.length - 1]; window_2.add(new JLabel(part)); if (!name.startsWith("private")){ System.out.println("Name: "+name); Object value = f.get((object.getClass().getSuperclass().cast(object))); window_2.add(new JTextField(value.toString())); } else { window_2.add(new JLabel("PRIVATE")); } } }
I'v tried using without the cast:PHP Code:Object value = f.get((object.getClass().getSuperclass().cast(object)));
But gives same error.PHP Code:Object value = f.get(object);
So what does this error meens, and how can I fix it?
- 09-15-2011, 09:35 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
Re: Get super class field value - Completly stuck -.-
Apparently it meens, "I cant access it because its default. It should be public or protected for me to work.".
Cryptic language..
- 09-16-2011, 09:34 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Gathering Data from a super class from a sub class
By kammce in forum New To JavaReplies: 2Last Post: 08-17-2011, 08:09 AM -
Referring to a super class
By blug in forum New To JavaReplies: 7Last Post: 03-20-2011, 05:06 AM -
super class reference variable accesses overriding sub class method
By subith86 in forum New To JavaReplies: 5Last Post: 01-26-2011, 06:38 PM -
super instanceof Class?
By mikeiz404 in forum New To JavaReplies: 11Last Post: 01-23-2009, 07:23 PM -
Class Reflection: Finding super class names
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks