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

    Red face Incompitable types, I'v tried every possible bypassing way but it just wont go away!

    Hai!
    I get the error seen in topic when Im using another script (that is imported) to get an array full of Buffered Image objects.
    Now It says: Incopmpitable types.
    Tho it is not!
    Im doing like this:
    Java Code:
    BufferedImage Images[] = LoadImages.Load()
    and that class is here:
    PHP Code:
    package src;
     
    import javax.imageio.*;
    import java.util.*;
    import java.awt.Image;
    import java.awt.image.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    
    public class LoadImages  {
    	
        static Vector <BufferedImage> list;
        //Character	
    	static File file = new File("C:\\Users\\Andreas\\Bilder\\MyCharacter\\Stand_1t.png");
    	static File file2 = new File("C:\\Users\\Andreas\\Bilder\\MyCharacter\\Stand_2t.png");
    	static File file3 = new File("C:\\Users\\Andreas\\Bilder\\MyCharacter\\Stand_1ta.png");
    	static File file4 = new File("C:\\Users\\Andreas\\Bilder\\MyCharacter\\Stand_2ta.png");
    
        public static BufferedImage Load()throws IOException{
        	try {
        		list = new Vector<BufferedImage>() ;
        		list.add(ImageIO.read(file));
    		    list.add(ImageIO.read(file2));
    		    list.add(ImageIO.read(file3));
    		    list.add(ImageIO.read(file4));
    		    BufferedImage list2[] = list.toArray();
    
        
        		return list2;
        	}catch(Exception e){
        		
        	}
        
        }
        
        
    }
    Now, Im confused what is wrong.. I'v tried ever sence yesterday to solve this cause I didnt wana make a big enojing message to you guys..
    But now I have like no choise.. Im stuck.
    Heres the main code that calls the Load method:
    PHP Code:
    /**
     * You must use Threading!
     */
     
    import src.LoadImages;
    import javax.swing.*;
    import javax.imageio.*;
    import java.awt.*;
    import java.awt.event.*; 
    import java.io.*;
    import java.awt.image.*;
    import java.awt.image.BufferedImage;
    import java.util.*;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    public class TestingArea  {
    	
    
        static Vector <Image> list = new Vector<Image>();
        static gameFrame gf;
        public static void main(String[] args) {
        	gf = new gameFrame();
        	gf.addKeyListener(new MyKeyListener());
        	paintIt obj = new paintIt();
        	try{
        		BufferedImage Images[] = LoadImages.Load();
        		obj.addPic(Images[0],Images[1],Images[2],Images[3]);
        		Player.SizeY = Images[0].getTileHeight(); //getHeight();
        	} catch (Exception e){
        	}
        	
        	gf.add(obj);
        	
        	javax.swing.Timer timer = new javax.swing.Timer(50,new MyTimerActionListener());
        	timer.start();
    
        }
        
        
    }
    
    class Player{
    	static int X = 0;
        static int Y = 0;
        static int[] CharVel = {10,10};
        static int SizeY;
        static int Friction = 2;
        //CharWalk [x,y]
        static int[] CharWalk = {0,0};
        static String isPressed = "";
        static String mode = "Walking";
        static boolean forward = true;
    }
    
    class MyKeyListener extends KeyAdapter{
    	public void keyPressed(KeyEvent ke){
    		char i = ke.getKeyChar();
    	    if (i=='a'){
    	    	Player.isPressed = "a";
    	    	Player.CharWalk[0] = -10;
    	    	Player.forward = true;
    	    }
    	   	if (i=='d'){
    	   		Player.isPressed = "d";
    	    	Player.CharWalk[0] = 10;
    	    	Player.forward = false;
    	    } 
    	    if (i=='w' && Player.mode == "Walking"){
    	    	Player.CharVel[1] = -10;
    	    } 
    	    	
    	}
    	public void keyReleased(KeyEvent ke){
    
    		char i = ke.getKeyChar();
    	    if (i=='a' && Player.isPressed == "a"){
    	    	Player.CharWalk[0] = 0;
    	    }
    	   	if (i=='d' && Player.isPressed == "d"){
    	    	Player.CharWalk[0] = 0;
    	    } 
    	}
    }
    
    	
    class MyTimerActionListener implements ActionListener {
      	public void actionPerformed(ActionEvent e) {
      		if (!(Player.Y+Player.SizeY+2> 400)){
      			Player.CharVel[1] += 2;
      		} else {
      			Player.CharVel[0] = (Player.CharVel[0]/Player.Friction);
      		}
        	if (Player.Y+Player.SizeY> 400){
        		
        		Player.CharVel[1] = -Player.CharVel[1]/2;
        		Player.Y = 400-Player.SizeY;
        	}
        	//System.out.println("Velocity: x: "+TestingArea.CharVel[0]+" y: "+TestingArea.CharVel[1]);
        	Player.Y += Player.CharVel[1];
        	//if (TestingArea.CharVel[1]<5 && TestingArea.CharVel[1] >-5){
        	//	TestingArea.Y = TestingArea.Y-TestingArea.CharVel[1];
        		//TestingArea.CharVel[1] = 0;
        		
        	//}
        	Player.X += Player.CharVel[0]+Player.CharWalk[0];
    
    
        	//Graphics g;
        	TestingArea.gf.repaint();
      	}
      	
      	
    }
    
    class gameFrame extends JFrame implements Runnable{
    	public void run(){
    		paintIt p = new paintIt();
    		add(p);
    	}
    	public gameFrame(){
    		
    		
    		
    		//paintIt p = new paintIt();
    		//add(p);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setSize(600,450);
    		setTitle("Image test");
    		setVisible(true);
    	}
    }
    
    class paintIt extends JPanel{
    	BufferedImage pic;
    	BufferedImage pic2;
    	BufferedImage pic3;
    	BufferedImage pic4;
    	int change = 0;
    	public void addPic(BufferedImage image,BufferedImage image2,BufferedImage image3,BufferedImage image4){
    		this.pic = image;
    		TestingArea.list.add(pic);
    		this.pic2 = image2;
    		this.pic3 = image3;
    		this.pic4 = image4;
    	}
    	
    	public void paintComponent(Graphics g){
    		super.paintComponent(g);
    		if (pic !=null && pic2 !=null && pic3 !=null && pic4 !=null){
    			change += 1;
    			if (Player.forward == false){
    
    				if (change <11){
    					g.drawImage(pic,Player.X,Player.Y,null);
    				}
    				if (change <20 && change >10){
    					g.drawImage(pic2,Player.X,Player.Y,null);
    				}
    				
    			} else {
    				if (change <11){
    					g.drawImage(pic3,Player.X,Player.Y,null);
    				}
    				if (change <20 && change >10){
    					g.drawImage(pic4,Player.X,Player.Y,null);
    				}
    				
    			}
    			if (change==19){
    				change = 0;
    			}
    			
    			
    			
    			g.setColor(Color.GREEN);
    			g.fillRect(1,400,1000,100);
    		}
    	}
    	
    }
    Appriciate all help! Thanks for reading :D

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Check the type of the return value of that Load method (method names should start with a lower case letter b.t.w.) and check the type of the variable where you want to stick that return value; are they the same or assignable types?

    kind regards,

    Jos

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

    Default

    Yes, thats the freaky part, they are!
    It returns an BufferedImage array, and the value that the class that called it is suppose to get is also a BufferedImage array..

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Addez View Post
    Yes, thats the freaky part, they are!
    It returns an BufferedImage array, and the value that the class that called it is suppose to get is also a BufferedImage array..
    Judging from your code your method returns a single BufferedImage and you want to store that as an array? There's nothing freaky about it, it is just wrong.

    kind regards,

    Jos

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

    Default

    Okej...
    Hows that possible?
    So anyways, I made a update to it so that the load function works like this:
    PHP Code:
    		    BufferedImage[] list2 = new BufferedImage[list.size()];
    		    for (int x = 0;x<list.size();x++){
    		    	list2[x] = list.elementAt(x); 
    		    }
    			//BufferedImage[] list2 = list2.toArray(BufferedImage[] list2);
        
        		return list2;
    Now, the list2 is a BufferedImage list containing not one, but all images..
    Still I get same error...
    I g2 b a true nob at java to not figure this out..

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    I reread your original post: your Load method states that it returns a BufferedImage but it wants to return an array of those images; fix that first.

    kind regards,

    Jos

Similar Threads

  1. Why wont my object render properly
    By toecutter in forum AWT / Swing
    Replies: 3
    Last Post: 10-22-2009, 01:43 PM
  2. why wont it compile
    By bje98f in forum Advanced Java
    Replies: 1
    Last Post: 04-23-2009, 10:55 PM
  3. save will work but load wont?!?!
    By Sticks_ll in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 04:19 AM
  4. [SOLVED] Last line in JTextArea wont display
    By Chris.Brown.SPE in forum Advanced Java
    Replies: 5
    Last Post: 04-11-2008, 01:52 PM
  5. simple problem - code wont compile
    By dirtycash in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 05:49 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
  •