Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int person_id=Integer.parseInt(person_id.getText());
- /*
- This person_id is taken from user from other class and called Person_detail class constructor which contains user interface code of this(Person_detail) class and set it visible(true) passed person id as:
- */
- Person_detail ob=new Person_detail();
- ob.setVisible(true);
- ob.person_id=person_id;
- ob.run();
- /*
- I am using class Person_detail implements Runnable.
- Code is like this:
- */
- int person_id;
- ExecutorService exec ;
- CompletableFuture<Void> t2;
- public void run()
- {
- Person_detail r = this;
- exec = Executors.newFixedThreadPool(3);
- CompletableFuture<Void> t1=CompletableFuture.runAsync(() -> r.pageload(),exec );
- t2=CompletableFuture.runAsync(() -> r.load_image(),exec );//line no. 612
- }
- synchronized void load_image()
- {
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con1=DriverManager.getConnection("jdbc:mysql://localhost:3306/"+dbsourcename,dbusername,dbpassword);
- Statement stmt1 = con1.createStatement();
- String sql1;
- sql1 = "SELECT photo FROM readers where person_id="+Integer.toString(person_id);
- ResultSet rs1 = stmt.executeQuery(sql1);//line no. 671
- rs1.next();
- if(rs1.getBlob("photo")!=null)
- { InputStream in = rs1.getBinaryStream("photo");
- OutputStream f = new FileOutputStream(new File("photo.jpg"));
- int c = 0;
- while ((c = in.read()) > -1)
- {
- f.write(c);
- }
- f.close();
- in.close();
- BufferedImage img = null;
- img = ImageIO.read(new File("photo.jpg"));
- Image dimg;
- dimg = img.getScaledInstance(jLabel9.getWidth(), jLabel9.getHeight(),Image.SCALE_SMOOTH);
- ImageIcon pho=new ImageIcon(dimg);
- jLabel9.setIcon(pho);
- new File("photo.jpg").deleteOnExit();
- } rs1.close();
- stmt1.close();
- con1.close();
- }catch(Exception e)
- {
- e.printStackTrace();
- JOptionPane.showMessageDialog(this,"Error : "+e,"Image display error",JOptionPane.ERROR_MESSAGE);
- }
- }
- /*
- Why sometimes I get Null pointer exception? (But sometimes not).
- java.lang.NullPointerException
- at librarymanagement.Person_detail.load_image(Person_detail.java:671)
- at librarymanagement.Person_detail.lambda$run$1(Person_detail.java:612)
- at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1626)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
- at java.lang.Thread.run(Thread.java:745)
- */
Add Comment
Please, Sign In to add comment