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

    Default The field "name" doesnt apparently exsist :/

    This code:

    PHP Code:
    try {
    				f.getClass().getField(txt).set(txt,real.substring(0,i));
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    Gives this error:
    PHP Code:
    Can not set java.lang.String field Window.name to java.lang.String
    Ehh wut?!

    Why cant it assign a string, to a string object?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default

    Because you dont read the API Doc *g*
    --> Field.set

    Parameters:
    obj - the object whose field should be modified
    value - the new value for the field of obj being modified

    try: set(f,real.substring(0,i));

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,998
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by Addez View Post
    This code:

    PHP Code:
    try {
    				f.getClass().getField(txt).set(txt,real.substring(0,i));
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    Gives this error:
    PHP Code:
    Can not set java.lang.String field Window.name to java.lang.String
    Ehh wut?!

    Why cant it assign a string, to a string object?
    You are referencing an incorrect object 'txt' in your getField( ... ) method; it should refer to the object to which you want to set its field. b.t.w. why are you using reflection?

    kind regards,

    Jos

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

    Default

    Ahhh okeee!!! :D
    I did read it, tho I didnt understand what they ment with object
    so I thought they ment object type like String and int etc :P

    Well, now I sorta fixed it, the window I belive, is a copy of the real..
    Because the window name doesnt change in any of the open windows, only in the one called this.f

    Heres a lil bit of my code:
    Java Code:
    public class AnimationManager {
    	
    	public static void text(Window f, String txt,String real,int time){
    		new Thread(new writeString(f).start();
    	}
    
    	
    }
    
    class writeString implements Runnable{
    
    	Window f;
    	
    	public writeString(Window f){
    		this.f = f;
    		
    	}
    	
    	private static void wait(int time){
    		try{
    			Thread.sleep(time);
    		} catch(Exception e){}
    	}
    
    	@Override
    	public void run(){
                 changing f here wouldnt change the f that we got in the text method right?
    If so, how can I change the text methods f from this method?
    		}
    	}

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Myself, I still am finding it hard to see what you're trying to do, but I also agree with the others that reflection doesn't smell right here. Consider creating and posting a small runnable version of your problem, an SSCCE.

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

    Default

    Well, my main idea is to have a method
    that I can call that would run in an extra thread, thus not
    hogging up the maincore.

    What I want it to do is to change values in a class instance called
    Window.

    Window "f" have the parameter-String "name"

    So I want to call a method text(f.name,"awsome",4000);
    Using that simple method, it would add a character, one at a time
    until f.name = "awsome"
    This should also only take 4000 miliseconds.

    That's what I want to do, and probebly I overcomplecated things eyy? :P

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

    Default

    lawls!
    Had forgot to update the repaint in the while loop :P
    So the actualy picture never updated :P

Similar Threads

  1. Replies: 3
    Last Post: 10-12-2010, 04:21 PM
  2. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  3. Replies: 4
    Last Post: 10-30-2009, 07:54 PM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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