Results 1 to 5 of 5
  1. #1
    Daniel R. is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default Some help on this exception: java.lang.NullPointerException: src image is null

    Hello,

    As the title of the post says I'm wondering how to solve this problem with my code. I'm using netbeans and my goal is to open an image and then apply some effects (like blur, scale, etc). I have 5 classes: the frameimage (where I have the buttons), a class where I have the effects, a class for the JFilechooser function, a class where I draw the image, and the main class. On the button named blur I call the blur component of the effects class: c.blur(); and I don't have any errors. The problem is when I run the program, open the image and then when I hit the "blur" button it gives me the error. Why?? I mean I had called the effect java class on the frameimage class and it still has this error.

    Thanks in advance for any ideas or help.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    What exception? Are we supposed to guess? Please provide relevant code, and the full stack trace, wrapped in code tags.

    [code]
    YOUR CODE HERE
    [/code]

    The more information you provide, the easier it gets for us to help you.

  3. #3
    orangetj is offline what you hate of yourself
    Join Date
    Jun 2011
    Posts
    16
    Rep Power
    0

    Default

    just asking here but you are doing this for educational purpose or are you hopping to achieve decent results in the pictures because If its for education purpose then you should check out Trail: 2D Graphics (The Java™ Tutorials)
    if you plan on actualy making the photos look better then they used to look either i recomend photoshop or waiting for a experienced scripter I only found the site a while back when I first started java... not much has changed since except for a couble of months

  4. #4
    Daniel R. is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default

    Hello again,

    the exception is on the title of the post: and the full log of the exception is this one:

    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: src image is null
    	at java.awt.image.ConvolveOp.filter(ConvolveOp.java:140)
    	at javaimagen.CPanel.blur(CPanel.java:87)
    	at javaimagen.frmImagen.jButton3ActionPerformed(frmImagen.java:126)
    	at javaimagen.frmImagen.access$300(frmImagen.java:22)
    	at javaimagen.frmImagen$4.actionPerformed(frmImagen.java:70)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    	at java.awt.Component.processMouseEvent(Component.java:6289)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    	at java.awt.Component.processEvent(Component.java:6054)
    	at java.awt.Container.processEvent(Container.java:2041)
    	at java.awt.Component.dispatchEventImpl(Component.java:4652)
    	at java.awt.Container.dispatchEventImpl(Container.java:2099)
    	at java.awt.Component.dispatchEvent(Component.java:4482)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    	at java.awt.Container.dispatchEventImpl(Container.java:2085)
    	at java.awt.Window.dispatchEventImpl(Window.java:2478)
    	at java.awt.Component.dispatchEvent(Component.java:4482)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
    	at java.awt.EventQueue.access$000(EventQueue.java:85)
    	at java.awt.EventQueue$1.run(EventQueue.java:603)
    	at java.awt.EventQueue$1.run(EventQueue.java:601)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    	at java.awt.EventQueue$2.run(EventQueue.java:617)
    	at java.awt.EventQueue$2.run(EventQueue.java:615)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    I didn't post the full exception and code because I thought maybe someone had already solved this in the past. Anyway the classes are the following:

    for the effects:

    Java Code:
    package javaimagen;
    
    import java.awt.Color;
    
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    
    import java.awt.Image;
    
    import java.awt.image.BufferedImage;
    import java.awt.image.ConvolveOp;
    import java.awt.image.Kernel;
    //import javax.imageio.ImageIO;
    //import java.net.URL;
    
    
    import javax.swing.JLabel;
    //import java.util.*;
    
    
     public class CPanel extends JLabel {
         
      
        
      Image displayImage;
    
      BufferedImage biSrc;
    
      BufferedImage biDest; // Destination image is mandetory.
    
      BufferedImage bi; // Referencia.
    
      Graphics2D big;
    
     
      public void createBufferedImages() {
           
           
       
        biSrc = new BufferedImage(displayImage.getWidth(this), displayImage
            .getHeight(this), BufferedImage.TYPE_INT_RGB);
    
        big = biSrc.createGraphics();
        big.drawImage(displayImage, 0, 0, this);
    
        biDest = new BufferedImage(displayImage.getWidth(this), displayImage
            .getHeight(this), BufferedImage.TYPE_INT_RGB);
      }
    
      public void sharpen() {
        float data[] = { -1.0f, -1.0f, -1.0f, -1.0f, 9.0f, -1.0f, -1.0f, -1.0f,
            -1.0f };
        Kernel kernel = new Kernel(3, 3, data);
        ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
            null);
        convolve.filter(biSrc, biDest);
        bi = biDest;
    
      }
    
      
    public static BufferedImage horizontalflip(BufferedImage img) {  
            int w = img.getWidth();  
            int h = img.getHeight();  
            BufferedImage dimg = new BufferedImage(w, h, img.getType());  
            Graphics2D g = dimg.createGraphics();  
            g.drawImage(img, 0, 0, w, h, w, 0, 0, h, null);  
            g.dispose();  
            return dimg;  
        }  
      
      
      public void blur() {
          
        
        
        float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f,
            0.0625f, 0.125f, 0.0625f };
        Kernel kernel = new Kernel(3, 3, data);
        ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
            null);
            BufferedImage filter = convolve.filter(biSrc, biDest);
        bi = biDest;
        
            biSrc = new BufferedImage(displayImage.getWidth(this), displayImage
            .getHeight(this), BufferedImage.TYPE_INT_RGB);
    
        big = biSrc.createGraphics();
        big.drawImage(displayImage, 0, 0, this);
    
        
            biDest = new BufferedImage(displayImage.getWidth(this), displayImage
            .getHeight(this), BufferedImage.TYPE_INT_RGB);
         
          BufferedImage buf = new BufferedImage(getWidth(),getHeight(),
                BufferedImage.TYPE_INT_RGB);
            super.paintComponent(buf.getGraphics());
            
            ConvolveOp op = new ConvolveOp(new Kernel(3,3, data));
            Image img = op.filter(buf,null);
           
        
      }
    
    
      
        public void edgeDetect() {
        float data[] = { 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f,
            -1.0f };
    
        Kernel kernel = new Kernel(3, 3, data);
        ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
            null);
        convolve.filter(biSrc, biDest);
    
        bi = biDest;
      }
    
      public void reset() {
        big.setColor(Color.black);
        big.clearRect(0, 0, bi.getWidth(this), bi.getHeight(this));
        big.drawImage(displayImage, 0, 0, this);
        bi = biSrc;
      }
    @Override
      public void update(Graphics g) {
        g.clearRect(0, 0, getWidth(), getHeight());
        paintComponent(g);
      }
    @Override
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2D = (Graphics2D) g;
    
        g2D.drawImage(bi, 0, 0, this);
      }
    
    }
    the frame image

    Java Code:
     
    package javaimagen;
    
    
    
    public class frmImagen extends java.awt.Frame {
         
       
          metodos m=new metodos();  [B]/*here I call the class metodos that is the one that contain the JFile Chooser*/[/B]
          CPanel c=new CPanel();  [B]// here I call the class where i have the effects[/B]
    
    
        /** Creates new form frmImagen */
        public frmImagen() {
            initComponents();
        }
    
        
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jPanel1 = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
    
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
                }
            });
    
            jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    
            jButton1.setText("Cargar Imagen");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
    
            jButton2.setText("Borrar Imagen");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
    
            jButton3.setLabel("sharpen");
            jButton3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton3ActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGap(51, 51, 51)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
                    .addGap(11, 11, 11)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(jButton3))
                    .addGap(7, 7, 7)
                    .addComponent(jButton2)
                    .addContainerGap())
            );
    
            pack();
        }// </editor-fold>                        
    
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {                          
            System.exit(0);
        }                         
    
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:
            m.Abrir_Dialogo(jPanel1);
        }                                        
    
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:
            jPanel1.removeAll();
            jPanel1.repaint();
    
        }                                        
    
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
           
            c.blur();       [B]//HERE THE COMPONENT BLUR[/B]
            
          
      
           
        }                                        
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new frmImagen().setVisible(true);
                    
                }
            });
        }
    
      
        
    
        
       
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JPanel jPanel1;
        // End of variables declaration                   
    
        
    }
    The code is messed up because I "played" with it a lot.

    Thanks

    @ orangetj: the goal is just educational purpose (for my own knowledge). BTW thanks for the link..

  5. #5
    orangetj is offline what you hate of yourself
    Join Date
    Jun 2011
    Posts
    16
    Rep Power
    0

    Default

    honestly you will need to post the whole log one thing i have learned from others mystakes is that 99% of the time you need the whole picture XD
    but right away I do notice that you seem to have forgot to tell the program an output comand which is like having a one way street with a dead end
    Last edited by orangetj; 06-12-2011 at 04:05 AM.

Similar Threads

  1. Replies: 17
    Last Post: 04-13-2011, 06:18 PM
  2. Replies: 1
    Last Post: 12-13-2010, 03:19 PM
  3. Replies: 3
    Last Post: 04-30-2010, 07:44 PM
  4. Replies: 5
    Last Post: 08-26-2009, 11:37 AM
  5. Replies: 1
    Last Post: 07-16-2007, 06:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •