-1

我目前正在使用离散小波变换进行隐写术项目。我已经编写了代码并编译了它。但是我面临一些异常。请帮助我解释异常。异常如下

        Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: null
        at java.lang.Integer.parseInt(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at DWT.dwtFunc(Steganography.java:292)
        at TextInput.actionPerformed(Steganography.java:252)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

我是 Stack Overflow 的新手。如果我在发布问题时犯了任何错误,请原谅我。谢谢你

回复:对不起先生,我仍然熟悉论坛的规则。

用于检测图像中皮肤区域的代码是

    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.image.BufferedImage;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    import java.io.*;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.FileFilter;
    import javax.swing.filechooser.FileNameExtensionFilter;
    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.lang.*;

    public class demo2
    {

        public void skindet()
        {
            float[] hsvval;
            float hue,sat,val;
            int counter = 0;
            String[] skinpixel = new String[200000];
            int scount = 0;
            try
            {

                BufferedImage image = ImageIO.read(new File("lena.png"));
                int[][] rgb=new int[550][550];
                int w = image.getWidth();
                int h = image.getHeight();
                hsvval=new float[3];
                int red,green,blue;
                for (int i=0;i<w;i++) 
                {
                    for (int j=0;j<h;j++)
                    {
                        rgb[i][j] =image.getRGB(i,j);
                        red=(rgb[i][j] >> 16) & 0xff;
                        green=(rgb[i][j] >> 8) & 0xff;
                        blue=(rgb[i][j]) & 0xff;
                        float[] values = Color.RGBtoHSB(red,green,blue,null);
                        for(int s=0;s<3;s++)
                        {
                            hsvval[counter]=values[s];
                            counter++;
                        }
                        hue=hsvval[0];
                        sat=hsvval[1];
                        val=hsvval[2];
                        if(hue>0 && hue<0.11 && sat>0.2 && sat<0.7)
                        {
                            String xcor=Integer.toString(i);
                            String ycor=Integer.toString(j);
                            skinpixel[scount]=xcor;
                            scount++;
                            skinpixel[scount]=ycor;
                            scount++;
                        }
                    }
                }
                int length=skinpixel.length;
                for(int i=0;i<length;i++)
                    System.out.println(skinpixel[i]+"\n");

            }

            catch(Exception e)
            {
                e.printStackTrace();
            }


        }

        public static void main(String args[])
        {

            demo2 dem=new demo2();
            dem.skindet();
        }

    }

例外是

java.lang.ArrayIndexOutOfBoundsException: 3 在 demo2.skindet(demo2.java:44) 在 demo2.main(demo2.java:79)

谢谢你的回复。问候

4

1 回答 1

2

这意味着您是Integer.parseInt从第 292 行调用的Steganography.java(它通常看起来包含一个名为DWT而不是的类Steganography),但您提供的是一个空值。

看起来这是对在文本字段上执行的某些操作的响应。

如果没有看到您的代码,我们真的无法说出更多信息——您需要弄清楚为什么该值为 null。

编辑:好的,现在它已更改为完全不同的错误,这就是问题所在:

int counter = 0;

hsvval=new float[3];
...
for (int i=0;i<w;i++) 
{
    for (int j=0;j<h;j++)
    {
        ...
        for(int s=0;s<3;s++)
        {
            hsvval[counter]=values[s];
            counter++;
        }
        ...          
    }
}

所以一次执行内部循环时,很好 - 但是在中间循环的第二次迭代(j = 1)中,你还没有 reset counter,所以它是 3 - 这超出了范围。你scount以后也有同样的问题。

如果您在它们用于内部循环之前count声明并初始化它们,那很好。scount

于 2012-04-18T14:42:53.813 回答