Results 1 to 3 of 3
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default 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:
    PHP Code:
    class dot extends point{
    int width = 0;
    }
    
    class point{
    int height = 10;
    }
    So I want to create a jlabel called width, and a jtextfield next to it which has the value "0".
    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.
    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"));
    					}
    				} 
    			}
    The error is at this line:
    PHP Code:
    Object value = f.get((object.getClass().getSuperclass().cast(object)));
    I'v tried using without the cast:
    PHP Code:
    Object value = f.get(object);
    But gives same error.

    So what does this error meens, and how can I fix it?

  2. #2
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default 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..

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,751
    Rep Power
    19

    Default Re: Get super class field value - Completly stuck -.-

    Not really cryptic if you know reflection.
    Fields have modifiers...private/public/protected/final etc are modifiers...yours has no modifier, hence "".

Similar Threads

  1. Replies: 2
    Last Post: 08-17-2011, 08:09 AM
  2. Referring to a super class
    By blug in forum New To Java
    Replies: 7
    Last Post: 03-20-2011, 05:06 AM
  3. Replies: 5
    Last Post: 01-26-2011, 06:38 PM
  4. super instanceof Class?
    By mikeiz404 in forum New To Java
    Replies: 11
    Last Post: 01-23-2009, 07:23 PM
  5. Class Reflection: Finding super class names
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •