'Could not find or load main class net.fabricmc.devlaunchinjector.Main fabricmc

I was programming a fabric minecraft mod in intellij and when I ran the code it said :

Could not find or load main class net.fabricmc.devlaunchinjector.Main

When I compiled the code and tried it in minecraft it worked, but in intellij i couldn't run it.



Solution 1:[1]

I was messing around with the files, to see if I can fix it and I found a solution :

  1. Go to "Run Configuration", press the arrow to see the options and tap "Edit Configurations" Go to "Minecraft Client" and press the button next to "net.fabricmc.devlaunchinjector.Main" search trough your external libraries and find "net.fabricmc.devlauncherinjector.Main" (it must be right under net.fabricmc-api...) select it, and after that you should see the "Edit Configurations" window. Press "OK"
  2. If this doesn't work, right click the file and select "Copy Full Path". Then go to "Edit Configurations" window and paste it where it says "net.fabricmc.devlauncherinjector.Main"
  3. If the 2 option doesn't work either, close the project, copy the mod folder, and paste it somewhere else(eg. Desktop, New Folder). And then open your IDE, go to open project and select the copied folder. Press the "Build.gradle" file and select open as project and "Trust" .It should now work. If it doesn't , unfortunately I don't know how to fix it.

Solution 2:[2]

In Intellij gradle if

this doesn't work you can put

downloadAssets runClient into a gradle config and it will start a client and download the net.fabricmc.devlauncherinjector.Main this allows you to use gradles built in Minecraft Client

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SD12
Solution 2 thecoopsyt