Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: Error code causing crash. Need help!  (Read 835 times)

Raif Redacted

  • Ensign
  • *
  • Posts: 22
    • View Profile
Error code causing crash. Need help!
« on: November 25, 2022, 06:58:32 PM »

Hi all

I've been asking for help through the unofficial Discord but the mod still just causes crashing, with errors like:

java.lang.NoClassDefFoundError: data.hullmods.BaseScienceHullMod

I looked up the error and it apparently means the file structure used to tell the game where things are (the package mod.location/import areas) is probably messed up in some way. I can't figure out why, as I've copied the original files and other peoples' mods formats to learn how to write it correctly. I must be missing something, a file I need to include or something is overlooked. Would love to ask for some help. It's a very small mod (zip with files is less than 20kb). Thanks in advance!

edit:

This is the top of the file mentioned in the error code:

package data.hullmods;

import campaign.ids.HullMods;
import campaign.ids.Stats;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.loading.HullModSpecAPI;

The first three lines are used in my mod, the other 4 are not. First obviously being the location of the file mentioned in the error code. The other two the modded location of those files (they're modified because I needed to add a string to each of them).
« Last Edit: November 25, 2022, 07:17:50 PM by Raif Redacted »
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Error code causing crash. Need help!
« Reply #1 on: November 25, 2022, 11:11:29 PM »

Just post the mod.

Also search the log for data.hullmods.BaseScienceHullMod, it may be writing an error when it fails to load.
Logged

Raif Redacted

  • Ensign
  • *
  • Posts: 22
    • View Profile
Re: Error code causing crash. Need help!
« Reply #2 on: November 26, 2022, 08:47:58 AM »

Just post the mod.

Also search the log for data.hullmods.BaseScienceHullMod, it may be writing an error when it fails to load.

Oh, ok, wasn't sure I was allowed to post the files. Thanks.

[attachment deleted by admin]
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Error code causing crash. Need help!
« Reply #3 on: November 26, 2022, 06:12:05 PM »

Is the zip deliberately incomplete? The mod_info.json references a LogisticsOverhaul.jar but no jar file exists in the zip; also there's no hull_mods.csv.

BaseScienceHullMod itself looks fine.

You're already on the Discord server so see if you can get someone to help you in real time; I'd do it but I'm tired.
Logged

Raif Redacted

  • Ensign
  • *
  • Posts: 22
    • View Profile
Re: Error code causing crash. Need help!
« Reply #4 on: November 26, 2022, 10:55:46 PM »

Is the zip deliberately incomplete? The mod_info.json references a LogisticsOverhaul.jar but no jar file exists in the zip; also there's no hull_mods.csv.

BaseScienceHullMod itself looks fine.

You're already on the Discord server so see if you can get someone to help you in real time; I'd do it but I'm tired.

Both those files exist, I just didn't include them. The jar intentionally, since it's essentially just a zip of the source folder. The CSV I forgot to add back in before attaching. I have asked for help on the discord server a handful of times over the last couple days. I got some help figuring out the CSV doesn't go into the jar (which is why it wasn't in that zip I attached), but otherwise, I haven't been able to get someone to really check if something is wrong. I'll add the jar and CSV into the zip now and re-attach, just in case you do get around to being able to figure something out, or anyone else. Just really want to find out what the issue is.

[attachment deleted by admin]
Logged

AtlanticAccent

  • Lieutenant
  • **
  • Posts: 73
    • View Profile
Re: Error code causing crash. Need help!
« Reply #5 on: November 27, 2022, 04:50:46 AM »

Both those files exist, I just didn't include them. The jar intentionally, since it's essentially just a zip of the source folder.

Whilst jars are just zips, they do not just contain .java source files. They include .class files, which are compiled versions of your .java files. I haven't checked properly yet, but probably
Quote
java.lang.NoClassDefFoundError: data.hullmods.BaseScienceHullMod
is a result of the game looking for a compiled version of your class in the jar file and not finding it.
Logged

Raif Redacted

  • Ensign
  • *
  • Posts: 22
    • View Profile
Re: Error code causing crash. Need help!
« Reply #6 on: November 27, 2022, 06:13:49 AM »

Both those files exist, I just didn't include them. The jar intentionally, since it's essentially just a zip of the source folder.

Whilst jars are just zips, they do not just contain .java source files. They include .class files, which are compiled versions of your .java files. I haven't checked properly yet, but probably
Quote
java.lang.NoClassDefFoundError: data.hullmods.BaseScienceHullMod
is a result of the game looking for a compiled version of your class in the jar file and not finding it.

Right, true. I don't know anything about java coding, but I was under the impression that including the compiled files made it harder to open them.

My (trial version of) intellij compiled the thing for me from the java file and in checking, they're all in there. I wonder if that means I missed something somewhere that tells the game to find the class file in the folder structure I have it in, rather than trying to find it in the original api.
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Error code causing crash. Need help!
« Reply #7 on: November 27, 2022, 06:18:50 AM »

Tried running the mod, figured out the problem:

BaseScienceHullMod has a static field
Code: java
public static int MAX_MODS = Global.getSettings().getInt("maxScienceHullmods");
There is no settings.json file containing maxScienceHullmods, so trying to get the value throws an exception
causing BaseScienceHullMod to silently fail to load
which broke the hullmods whose Java classes derived from BaseScienceHullMod

Fixed by adding a file data/config/settings.json to the mod with the required value.

Code: json
{
"maxScienceHullmods":2,
}
Logged

Raif Redacted

  • Ensign
  • *
  • Posts: 22
    • View Profile
Re: Error code causing crash. Need help!
« Reply #8 on: November 27, 2022, 07:06:45 AM »

Tried running the mod, figured out the problem:

BaseScienceHullMod has a static field
Code: java
public static int MAX_MODS = Global.getSettings().getInt("maxScienceHullmods");
There is no settings.json file containing maxScienceHullmods, so trying to get the value throws an exception
causing BaseScienceHullMod to silently fail to load
which broke the hullmods whose Java classes derived from BaseScienceHullMod

Fixed by adding a file data/config/settings.json to the mod with the required value.

Code: json
{
"maxScienceHullmods":2,
}

Sigh... this is what I was afraid of seeing, something that makes perfect sense and would likely have been a step 2 if I had just a bit more experience. The last few days, I've been thinking that my not having a modPlugin file or something similar was likely the issue. I also don't have a manifest file created, but I doubt that really matters at all (also, I don't know what settings to choose to let intellij make it, despite seeing the option). Thank you for finding the problem. I had about 95% of this fully done inside the first 2 or 3 hours days ago, then for about 16 hours after that, I was desperately trying to find the problem while asking for help.
Logged