Guest User

lib

a guest
Aug 1st, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. int person_id=Integer.parseInt(person_id.getText());
  2. /*
  3. 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:
  4. */
  5. Person_detail ob=new Person_detail();
  6. ob.setVisible(true);
  7. ob.person_id=person_id;
  8. ob.run();
  9.  
  10. /*
  11. I am using class Person_detail implements Runnable.
  12. Code is like this:
  13. */
  14. int person_id;
  15. ExecutorService exec ;
  16. CompletableFuture<Void> t2;
  17. public void run()
  18. {
  19. Person_detail r = this;
  20. exec = Executors.newFixedThreadPool(3);
  21. CompletableFuture<Void> t1=CompletableFuture.runAsync(() -> r.pageload(),exec );
  22. t2=CompletableFuture.runAsync(() -> r.load_image(),exec );//line no. 612
  23. }
  24. synchronized void load_image()
  25. {
  26. try{
  27. Class.forName("com.mysql.jdbc.Driver");
  28. Connection con1=DriverManager.getConnection("jdbc:mysql://localhost:3306/"+dbsourcename,dbusername,dbpassword);
  29. Statement stmt1 = con1.createStatement();
  30. String sql1;
  31. sql1 = "SELECT photo FROM readers where person_id="+Integer.toString(person_id);
  32. ResultSet rs1 = stmt.executeQuery(sql1);//line no. 671
  33. rs1.next();
  34. if(rs1.getBlob("photo")!=null)
  35. { InputStream in = rs1.getBinaryStream("photo");
  36. OutputStream f = new FileOutputStream(new File("photo.jpg"));
  37. int c = 0;
  38. while ((c = in.read()) > -1)
  39. {
  40. f.write(c);
  41. }
  42. f.close();
  43. in.close();
  44. BufferedImage img = null;
  45. img = ImageIO.read(new File("photo.jpg"));
  46. Image dimg;
  47. dimg = img.getScaledInstance(jLabel9.getWidth(), jLabel9.getHeight(),Image.SCALE_SMOOTH);
  48. ImageIcon pho=new ImageIcon(dimg);
  49. jLabel9.setIcon(pho);
  50. new File("photo.jpg").deleteOnExit();
  51. } rs1.close();
  52. stmt1.close();
  53. con1.close();
  54. }catch(Exception e)
  55. {
  56. e.printStackTrace();
  57. JOptionPane.showMessageDialog(this,"Error : "+e,"Image display error",JOptionPane.ERROR_MESSAGE);
  58. }
  59. }
  60. /*
  61. Why sometimes I get Null pointer exception? (But sometimes not).
  62. java.lang.NullPointerException
  63. at librarymanagement.Person_detail.load_image(Person_detail.java:671)
  64. at librarymanagement.Person_detail.lambda$run$1(Person_detail.java:612)
  65. at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1626)
  66. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  67. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  68. at java.lang.Thread.run(Thread.java:745)
  69. */
Add Comment
Please, Sign In to add comment