java

anyone with java knowledge?,
cant understand where the nullpointerexception is.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
    
public class HandleMedia{
    	
    public static void main(String[] args) throws Exception{
    	int imagecounter = 0;
    	rita r = new rita("C:\\Users\\root\\Desktop\\create\\"+imagecounter+".jpeg");

   		JFrame frame = new JFrame();
   		frame.setTitle("Stream");
   		frame.setVisible(true);
   		frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
   		frame.setSize(100,100);
    	frame.add(r);
    		
    	
   		Robot robot = new Robot();
   		
   		for(int x = 0;x < x+1; x++){
   			String path = "C:\\Users\\root\\Desktop\\create\\"+imagecounter+".jpeg";
    	  	    	
   			BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
   			ImageIO.write(screenShot, "JPG", new File(path));
   			imagecounter ++;
    	
   		}		
    }	
 }

class rita extends JPanel{
	
	Image bild = null;
	String path;
	
	public rita(String pic){
    	path = pic;
    	setImage();
	}
	
	public void paint(Graphics g){
		super.paint(g);
		this.setBackground(Color.BLUE);
		g.drawImage(bild, 0, 0, this);
		repaint();
	}
	
   	public void setImage(){
		try{
			URL imageURL = HandleMedia.class.getResource(path);
			bild = Toolkit.getDefaultToolkit().getImage(imageURL);
		}
		catch (Exception e){
			System.out.println("Error - "+e.getMessage());
		}
   	}
}
1
2
for(int x = 0;x < x+1; x++){//this is an infinite loop
String path = "C:\\Users\\root\\Desktop\\create\\"+imagecounter+".jpeg";//are you sure this path exists? 
Last edited on
Now its only a error machine soon if anyone got any ides


added timer, lable to for images



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
    
public abstract class HandleMedia{
	
	
	
    public static void main(String[] args) throws Exception{
    	int imagecounter = 0;
    	rita r = new rita("C:\\Users\\root\\Desktop\\create\\"+imagecounter+".jpeg");

   		JFrame frame = new JFrame();
   		frame.setTitle("Stream");
   		frame.setVisible(true);
   		frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
   		frame.setSize(100,100);
    	frame.add(r);
    	int count = 0;
    	
 
   		Robot robot = new Robot();

   		for(int x = 0;x < x+1; x++){
   			
   			String path = "C:\\Users\\root\\Desktop\\create\\"+imagecounter+".jpeg";

   			BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
   			ImageIO.write(screenShot, "JPG", new File(path));
   			imagecounter ++;
   			System.out.println(imagecounter);
   			JLabel lable = new JLabel();
   			ImageIcon image = new ImageIcon(path);
   			lable.setIcon(image);
   			frame.add(lable);
    	
   		}		
    }
 }

class rita extends JPanel implements ActionListener{
	
	Image bild = null;
	String path;
	private Timer time = new Timer(1000, this);;
	public int count = 0;
	
	
	public rita(String pic){
    	path = pic;
    	setImage();
    	timeStart();
	}


	public void paint(Graphics g){
		super.paint(g);
		g.drawImage(bild, 0, 0, this);
	}
	
   	public void setImage(){
		try{
			URL imageURL = HandleMedia.class.getResource(path);
			bild = Toolkit.getDefaultToolkit().getImage(imageURL);
		}
		catch (Exception e){
			System.out.println("Error - "+e.getMessage());
		}
   	}

   	public void timeStart(){
   		time.start();
   	}
   	public void timeStop(){
   		time.stop();
   	}
	@Override
	public void actionPerformed(ActionEvent e) {
		count++;
		System.out.println(count);
		setImage();
   		repaint();
	}
}
Last edited on
The NPE is where it shows it is - you should get a stackrace.
Kk works,
Like this first time you play it it records with printscreens the next time you play, it is a "video" that replays what you did, ty for help all.


The recording will only get longer and longer if you dont delete the screenshots between the restarts of the program


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
    
public abstract class HandleMedia{
	
	
	
    public static void main(String[] args) throws Exception{
    	int imagecounter = 0;
   		JFrame frame = new JFrame();
   		rita r = new rita("C:\\Users\\root\\Desktop\\create\\"+imagecounter+".jpeg", imagecounter);
   		frame.setTitle("Stream");
   		frame.setVisible(true);
   		frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
	   	frame.setSize(1366,768);
	   	frame.add(r);
		String path = "C:\\Users\\root\\Desktop\\create\\"+imagecounter+".jpeg";
    	
		JLabel lable = new JLabel();
  		frame.add(lable);
 
   		Robot robot = new Robot();

   		for(int x = 0;x < x+1; x++){
   			imagecounter++;
   			BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
   			ImageIO.write(screenShot, "JPG", new File(path));
   			imagecounter ++;
   			System.out.println(imagecounter);
   			if (imagecounter <= 10)
   				r.timeStop();
   			
   			path = "C:\\Users\\root\\Desktop\\create\\"+imagecounter+".jpeg";
   		    r.update(path, imagecounter);
   	   		ImageIcon image = new ImageIcon(path);
   	  		lable.setIcon(image);
   	   		frame.repaint();    	
   		}		
    }
 }

class rita extends JPanel implements ActionListener{
	
	Image bild = null;
	String path;
	private Timer time = new Timer(1, this);;
	public int  count = 0;
	public int imagecounter = 0;
	
	
	public rita(String pic, int point){
    	timeStart();
	}
	public void update(String pic, int x){
		path = pic;
		count = x;
		setImage();
		
	}


	public void paint(Graphics g){
		super.paint(g);
		g.drawImage(bild, 0, 0, this);
	}
	
   	public void setImage(){
		try{
			URL imageURL = HandleMedia.class.getResource(path);
			bild = Toolkit.getDefaultToolkit().getImage(imageURL);
		}
		catch (Exception e){
			System.out.println("Error - "+e.getMessage());
		}
   	}

   	public void timeStart(){
   		time.start();
   	}
   	public void timeStop(){
   		time.stop();
   	}
	@Override
	public void actionPerformed(ActionEvent e) {
		count++;
		setImage();
   		repaint();
   		update(path, count);
		imagecounter = count;
	}
}
Last edited on
Topic archived. No new replies allowed.