java.lang.classnotfoundexception: org.firmata4j.iodevice

问题描述 投票:0回答:1

这个错误让我彻夜难眠。我不知道如何解决它,我浏览了互联网上每个论坛的每个类似问题,但找不到任何解决方法。看起来很简单,一个连接arduino的minecraft mod。但出于某种原因,gradle/intellij/minecraft 不允许我导入 IODevice。我不知道出了什么问题。有人请帮助我。

我的代码


import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.firmata4j.Pin;
import org.firmata4j.firmata.FirmataDevice;
import org.firmata4j.IODevice;

import java.io.IOException;
import java.util.List;

@Mod(ArduinoDamageMod.MODID)
public class ArduinoDamageMod {

    public static final String MODID = "arduinodamagemod";
    private IODevice arduino;
    private boolean isArduinoConnected = false;

    @SubscribeEvent
    public void onInitialize() {
        String PORT = "/dev/cu.usbmodem11202";
        try {
            arduino = new FirmataDevice(PORT);
            arduino.start();
            arduino.ensureInitializationIsDone();
            isArduinoConnected = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (!isArduinoConnected) {
            System.err.println("Failed to connect to Arduino!");
        }

        // Register event handlers
        MinecraftForge.EVENT_BUS.register(this);
    }

    @SubscribeEvent
    public void onShutdown() throws IOException {
        if (arduino != null) {
            arduino.stop();
        }
    }

    @Mod.EventBusSubscriber
    public static class EventHandler {
        @SubscribeEvent
        public void onPlayerDamage(LivingHurtEvent event) {
            if (event.getEntity() instanceof Player player) {
                // Turn on the LED on the Arduino for 3 seconds
                ArduinoDamageMod.getInstance().turnOnLed();
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                ArduinoDamageMod.getInstance().turnOffLed();
                }
        }
    }

    public void turnOnLed() {
        if (isArduinoConnected) {
            try {
                // Set pin 6 to output mode and set its value to high
                arduino.getPin(6).setMode(Pin.Mode.OUTPUT);
                arduino.getPin(6).setValue(1);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void turnOffLed() {
        if (isArduinoConnected) {
            try {
                // Set pin 6 to output mode and set its value to low
                arduino.getPin(6).setMode(Pin.Mode.OUTPUT);
                arduino.getPin(6).setValue(0);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private static ArduinoDamageMod instance;
    public static ArduinoDamageMod getInstance() {
        return instance;
    }
}

完整的错误信息:

// Hey, that tickles! Hehehe!

Time: 2023-04-07 16:43:34
Description: Mod loading error has occurred

java.lang.Exception: Mod Loading has failed
    at net.minecraftforge.logging.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:58) ~[forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp.jar:?] {re:classloading}
    at net.minecraftforge.client.loading.ClientModLoader.completeModLoading(ClientModLoader.java:165) ~[forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:591) ~[forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.Util.ifElse(Util.java:420) ~[forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp.jar:?] {re:classloading}
    at net.minecraft.client.Minecraft.lambda$new$3(Minecraft.java:585) ~[forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.gui.screens.LoadingOverlay.render(LoadingOverlay.java:135) ~[forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.GameRenderer.render(GameRenderer.java:940) ~[forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1160) ~[forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.run(Minecraft.java:731) ~[forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.main.Main.main(Main.java:205) ~[forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
    at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
    at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:25) ~[fmlloader-1.19.4-45.0.43.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?] {}
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?] {}
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?] {}
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?] {}
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?] {}
    at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
    at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?] {}
-- MOD arduinodamagemod --
Details:
    Caused by 0: java.lang.NoClassDefFoundError: org/firmata4j/IODevice
        at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?] {}
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?] {}
        at java.lang.Class.getConstructor0(Class.java:3578) ~[?:?] {}
        at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}
        at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.4-45.0.43.jar%23183!/:?] {}
        at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.4-45.0.43.jar%23186!/:?] {}
        at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}
        at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}
        at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}
        at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}

    Mod File: /Users/braden/coding/java/ADM/build/resources/main/
    Failure message: ArduinoDamageMod (arduinodamagemod) has failed to load correctly
        java.lang.NoClassDefFoundError: org/firmata4j/IODevice
    Mod Version: 0.0NONE
    Mod Issue URL: NOT PROVIDED
    Exception message: java.lang.ClassNotFoundException: org.firmata4j.IODevice
Stacktrace:
    at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?] {}
    at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}
    at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:137) ~[securejarhandler-2.1.6.jar:?] {}
    at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}
    at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:137) ~[securejarhandler-2.1.6.jar:?] {}
    at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}
    at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?] {}
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?] {}
    at java.lang.Class.getConstructor0(Class.java:3578) ~[?:?] {}
    at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}
    at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.4-45.0.43.jar%23183!/:?] {}
    at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.4-45.0.43.jar%23186!/:?] {}
    at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}
    at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}
    at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}
    at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}


-- System Details --
Details:
    Minecraft Version: 1.19.4
    Minecraft Version ID: 1.19.4
    Operating System: Mac OS X (aarch64) version 13.0.1
    Java Version: 17.0.5, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode, sharing), Oracle Corporation
    Memory: 125078016 bytes (119 MiB) / 597688320 bytes (570 MiB) up to 2147483648 bytes (2048 MiB)
    CPUs: 8
    Processor Vendor: Apple Inc.
    Processor Name: Apple M1
    Identifier: Apple Inc. Family 0x1b588bb3 Model 0 Stepping 0
    Microarchitecture: ARM64 SoC: Firestorm + Icestorm
    Frequency (GHz): 3.20
    Number of physical packages: 1
    Number of physical CPUs: 8
    Number of logical CPUs: 8
    Graphics card #0 name: Apple M1
    Graphics card #0 vendor: Apple (0x106b)
    Graphics card #0 VRAM (MB): 0.00
    Graphics card #0 deviceId: unknown
    Graphics card #0 versionInfo: unknown
    Memory slot #0 capacity (MB): 0.00
    Memory slot #0 clockSpeed (GHz): 0.00
    Memory slot #0 type: unknown
    Virtual memory max (MB): 15360.00
    Virtual memory used (MB): 13080.55
    Swap memory total (MB): 7168.00
    Swap memory used (MB): 6065.19
    JVM Flags: 1 total; -Xss1M
    ModLauncher: 10.0.8+10.0.8+main.0ef7e830
    ModLauncher launch target: forgeclientuserdev
    ModLauncher naming: mcp
    ModLauncher services: 
        mixin-0.8.5.jar mixin PLUGINSERVICE 
        eventbus-6.0.3.jar eventbus PLUGINSERVICE 
        fmlloader-1.19.4-45.0.43.jar slf4jfixer PLUGINSERVICE 
        fmlloader-1.19.4-45.0.43.jar object_holder_definalize PLUGINSERVICE 
        fmlloader-1.19.4-45.0.43.jar runtime_enum_extender PLUGINSERVICE 
        fmlloader-1.19.4-45.0.43.jar capability_token_subclass PLUGINSERVICE 
        accesstransformers-8.0.4.jar accesstransformer PLUGINSERVICE 
        fmlloader-1.19.4-45.0.43.jar runtimedistcleaner PLUGINSERVICE 
        modlauncher-10.0.8.jar mixin TRANSFORMATIONSERVICE 
        modlauncher-10.0.8.jar fml TRANSFORMATIONSERVICE 
    FML Language Providers: 
        [email protected]
        lowcodefml@null
        javafml@null
    Mod List: 
        forge-1.19.4-45.0.43_mapped_official_1.19.4-recomp|Minecraft                     |minecraft                     |1.19.4              |COMMON_SET|Manifest: a1:d4:5e:04:4f:d3:d6:e0:7b:37:97:cf:77:b0:de:ad:4a:47:ce:8c:96:49:5f:0a:cf:8c:ae:b2:6d:4b:8a:3f
        main                                              |ArduinoDamageMod              |arduinodamagemod              |0.0NONE             |ERROR     |Manifest: NOSIGNATURE
                                                          |Forge                         |forge                         |45.0.43             |COMMON_SET|Manifest: NOSIGNATURE
    Crash Report UUID: e2085851-7cc1-48d8-a918-3263a1481f3d
    FML: 45.0
    Forge: net.minecraftforge:45.0.43```
java gradle arduino minecraft minecraft-forge
1个回答
0
投票

你应该使用

shadowJar
/
fatJar
来生成 jar 文件,可能的原因是库没有被包含在构建时。

Gradle 构建文件取自。 https://gist.github.com/Commoble/ddc75e819a690198c15d26564d139333

// thanks to gigaherz for pointing me in the right directions on the buildscript

// The shadow gradle plugin assists with repackaging a 3rd-party library jar within your own jar
// In addition to ensuring that your end-users have the library available when they use your own thing,
// it also helps avoid collisions with other things that are also using the same library.

// As always, make sure the license of the library allows redistribution and is compatible with
// your own thing's license before redistributing it in this manner

buildscript {
    repositories {
        jcenter() // buildscript repo to get shadow from
    }
}

plugins {
    // this version works on gradle 4.9
    // more recent versions of shadow work on more recent versions of gradle
    id 'com.github.johnrengelman.shadow' version '4.0.4'
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java' // java plugin is needed for the shadow plugin to work

repositories {
    // java repo to get the repackaged lib from
    maven { url "https://repo.for/your/included/lib" }
}

configurations {
    shade
}

dependencies {
    compile "lib.group:lib_artifact:lib_version"
    shade "lib.group:lib_artifact:lib_version"
}

shadowJar {
    classifier = ''
    configurations = [project.configurations.shade]
    relocate 'lib.group', "${project.group}.shadow.lib.group" // ensure repackaged packages have unique names
}

reobf {
    shadowJar { }
}

// this replaces jar.finalizedBy('reobfJar') in the standard forge mod buildscript
tasks.build.dependsOn reobfShadowJar
jar.finalizedBy('reobfShadowJar')

您也可以按照本指南进行操作。 https://gist.github.com/SizableShrimp/949e7c219bfc94487a45226b64ac7749

© www.soinside.com 2019 - 2024. All rights reserved.