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:
Code:
BufferedImage Images[] = LoadImages.Load()
and that class is here:
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:
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