In the program I download a picture, check the folder, there it is there. I try to draw it, throws a java.lang.NullPointerException .
I restart the prog, the picture does not download, since there is a check for its existence. I try to draw - everything works.
Does java roughly say "screenshot" of the system at startup, and then does not respond to new files? If so, how to fix it?
//ΡΠ½Π°ΡΠ°Π»Π° ΠΏΡΠΎΠΈΡΡ
ΠΎΠ΄ΠΈΡ Π·Π°Π³ΡΡΠ·ΠΊΠ° Ρ ΡΠ°ΠΉΡΠ° private void getPictureFromWeatherSite(Forecast forecast){ String fileName = "C:\\Users\\alexandr\\Desktop\\Java\\weather\\src\\main\\java\\pictures\\" + forecast.returnUrlForecastImage(). substring(forecast.returnUrlForecastImage().lastIndexOf("/")); if (!(new File(fileName)).exists()) { new Downloader("http:"+ forecast.returnUrlForecastImage(), fileName); } } //Π·Π°ΡΠ΅ΠΌ ΡΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΎΠ±ΡΠ΅ΠΊΡΠ° Π½Π° ΠΎΡΠ½ΠΎΠ²Π΅ ΡΠΊΠ°ΡΠ°Π½Π½ΠΎΠΉ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ weatherTable.getColumnModel().getColumn(0).setCellRenderer( new ImageRenderer(data, "pictures" + forecast.returnUrlForecastImage(). substring(forecast.returnUrlForecastImage().lastIndexOf("/")))); But the class that deals with rendering
class ImageRenderer extends DefaultTableCellRenderer { private JLabel lbl = new JLabel(); private Object[][] data; private String picture; ImageRenderer(Object[][] data, String picture){ this.picture = picture; this.data = data; } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if(row == 1) { ImageIcon icon = new ImageIcon(getClass().getResource(picture)); lbl.setText(""); lbl.setIcon(icon); } else { lbl.setText((String) data[row][column]); lbl.setIcon(null); } return lbl; } } // ΠΊΠΎΠ΄ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ (model - DefaultTableModel) public void changeData(String date){ for(int i=3; i>=0; i--) model.removeRow(i); setData(date); for(int i=0; i<data.length; i++){ model.insertRow(i, data[i]); } weatherTable.setModel(model); Forecast forecast = getCurrentForecast(sinoptik.returnForecasts(), date); weatherTable.getColumnModel().getColumn(0).setCellRenderer( new ImageRenderer(data, "pictures" + forecast.returnUrlForecastImage(). substring(forecast.returnUrlForecastImage().lastIndexOf("/")))); forecast = getCurrentForecast(gismeteo.returnForecasts(), date); weatherTable.getColumnModel().getColumn(1).setCellRenderer( new ImageRenderer(data, "pictures" + forecast.returnUrlForecastImage(). substring(forecast.returnUrlForecastImage().lastIndexOf("/")))); }