Java MemoryClassLoader(IllegalArgumentException)

标签 java class memory loader encryption

我有一个内存类加载器 ( here ),我正在自定义 Minecraft 启动器中使用它。

Memory Class Loader

每当我加载 Minecraft(一款 Java LWJGL 游戏)时,都会收到以下错误:

27 achievements
182 recipes
Setting user
LWJGL Version: 2.4.2
java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at lc.<init>(SourceFile:21)
at gi.<init>(SourceFile:10)
at net.minecraft.client.Minecraft.a(SourceFile:254)
at net.minecraft.client.Minecraft.run(SourceFile:657)
at java.lang.Thread.run(Unknown Source)

我正在创建这样的类加载器:

Base.cLoader = new CLoader(
    GameUpdater.classLoader,
    new JarInputStream(new ByteArrayInputStream(jarFileBytes)));

如您所见,它成功加载了第一部分,然后在 LWJGL 版本之后突然崩溃并显示“input == null”。

编辑 - 这是新的 getResource 方法。
错误出现在“URL()”上,如图所示。

Image

代码:

public URL getResource(final String name) {
    URL url = new URL() { public InputStream openStream() {
        return new ByteArrayInputStream((byte[])others.get(name));
    }};

    return url;
}

最佳答案

一个疯狂的猜测...可能是这样的:警告:此 URL 尚未实现!您不能调用 getResource() 或 getResources()!

因此您的代码期望使用未实现的方法从 JAR 中检索图像。可能正在执行与此等效的操作:

ImageIO.read(memClassLoader.getResource(someString));

除此之外,正如我们所见,从 getResource 抛出的错误被忽略,并且 null 被用作值。 ImageIO.read像这样:

public static BufferedImage read(URL input) throws IOException {
    if (input == null) {
        throw new IllegalArgumentException("input == null!");
    }

    InputStream istream = null;
    try {
        istream = input.openStream();
    } catch (IOException e) {
        throw new IIOException("Can't get input stream from URL!", e);
    }
}

听起来很熟悉吗?因此,这大致就是您需要实现的内容:

public URL getResource(final String name) {
  try {
    return new URL("", "", 0, "",
        new URLStreamHandler() { public URLConnection openConnection(URL url) {
          return new URLConnection(url) {
            public void connect() {}
            public InputStream getInputStream() {
              // return the appropriate InputStream, based on the name arg
            }
          };
        }});
  } catch (MalformedURLException e) { throw new RuntimeException(e); }
}

关于Java MemoryClassLoader(IllegalArgumentException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10124541/

相关文章:

c# - 我是否需要在 .NET 中显式调整堆栈大小?

java - 将 Value bean/java 传递给 servlet

java - 线程中的异常 "main"java.lang.NoclassDefFoundError : cal/class

Python/Psychopy : Instantiating multiple circle objects from a class

java - 无法调用我的字符串函数

swift - 如何在另一个 View Controller 中从一个 View Controller 引用变量(选择器 View 值)?

java - 如何将泛型用于不同类的相似方法

java - 从 ListView 中隐藏/显示 ImageView

memory - 当 VRAM 已满时会发生什么?

memory - 澄清: Processor operates at 800 Mhz and 200Mhz DDR RAM