小编Die*_*unX的帖子

为什么我得到java.lang.NullPointerException?

我试图让Java applet来获取用户的MAC地址,将其转换为MD5,并将其发送到JavaScript函数,因此它可以做的东西.

我打算将此MD5附加到其他一些输入数据的表单中.

到目前为止,我可以检索MAC地址并成功将其转换为MD5.我不能做的是将它传递给我的javascript函数.

这是我的HTML代码:

<body>
<script type="text/javascript">
        function dohash(hash) { alert(hash); }
    </script>
<APPLET code="start.class" width="200" height="200"></APPLET>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是JAVA代码:

import netscape.javascript.JSObject;
import java.applet.*;
import java.security.*;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.math.BigInteger;

public class start extends Applet {

    private static final long serialVersionUID = 1L;
    JSObject win;

    public void main() {
        win = (JSObject)JSObject.getWindow(this);
    }

    public void init() {
        InetAddress ip;
        String hashtext = "a";
        try {
            ip = InetAddress.getLocalHost();

            NetworkInterface network = NetworkInterface.getByInetAddress(ip);

            byte[] …
Run Code Online (Sandbox Code Playgroud)

java nullpointerexception

-3
推荐指数
1
解决办法
1560
查看次数

标签 统计

java ×1

nullpointerexception ×1