你好,

每当我尝试使用ClassNode接受ClassWriter时,它都会引发NullPointerException。我有办法解决这个问题吗?

这是错误:

Caused by: java.lang.NullPointerException
    at org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:340)
    at net.winneonsword.WCClient.asm.WCClassTransformer.transform(WCClassTransformer.java:119)
    at net.winneonsword.WCClient.asm.WCClassTransformer.transform(WCClassTransformer.java:64)
    at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:274)
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:172)
    ... 9 more


这是它正在谈论的地方:

ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);

node.accept(writer);

bytes = writer.toByteArray();


这是完整的方法:

private byte[] transform(PatchInfo patch, byte[] z){

    boolean patched = false;
    byte[] bytes = z;

    ClassNode node = new ClassNode();
    ClassReader reader = new ClassReader(bytes);

    reader.accept(node, 0);

    WCLog.fine("Patching Class: %s", new Object[] { patch.target });

    HashMap<MethodNode, MethodNode> replace = new HashMap();

    for (MethodNode target : node.methods){

        for (MethodInfo method : patch.methods){

            if ((method.name.equals(method.name) || method.name.equals(method.mappedName))
                    && (method.desc.equals(method.desc) || method.desc.equals(method.mappedDesc))){

                MethodNode replacement = this.getReplacementMethod(patch, method);

                replace.put(target, replacement);
                WCLog.fine("Successfully Patched: %s at %s", new Object[] { method.name, method.desc });

                patched = true;

            }

        }

    }

    if (patched){

        for (MethodNode method : replace.keySet()){

            MethodNode replacement = replace.get(method);

            node.methods.remove(method);
            node.methods.add(replacement);

        }

        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);

        node.accept(writer);

        bytes = writer.toByteArray();

    }

    return bytes;

}


有人对如何解决这个问题有任何想法吗?

最佳答案

当您在其上调用node时,错误消息将提示您nullaccept()。您在那行之前以某种方式初始化了吗?

10-05 21:33