r/javahelp • u/TheScottishKreig • Nov 26 '20
I just don't understand
Bit of an open ended question here but I'm at my wits end, I come from a background of 7+ years programming in c#, Javascript and python so I thought "I'll try out some Java", started a small project, got it running, happy days. I realised Java was pretty similar to what I already knew so decided to make something I'd actually want to use and here's where the problem begins.
I've tried creating an android app which after 2 days of trying to get the blank template to run using both Android studio and intellij I gave up because I couldn't even start writing code.
Now I'm trying to create a plugin for a game I play, I generate a template from their git (it's pretty basic, just a test project that loads their client and injects my project), follow all the instructions and get hit with a "Main method not found" error, I spend 2 hours debugging and trying to get it working to no avail, I've messed with module settings, sdk versions, reinstalling intellij, invalidating the cache, I can't get it to run at all and yet clearly it works since tonnes of people have made plugins, am I missing some fundamental knowledge of Java required to just get shit to work or is this just me?
(I've probably tried to create around 4-5 different projects in Java only for them to have all been halted by some sort of undiagnosable compiler issue)
15
u/ryosen Extreme Brewer Nov 27 '20
“Main method not found” happens because, not surprisingly, the compiler cannot find a main() method in the starting class. This is typically caused by not telling the IDE which of your classes is the primary class, which one should be called first.
So, the first question here is are you sure that you have configured the project correctly? If so, and it has a main method, is that method declared correctly?
3
u/TheScottishKreig Nov 27 '20
This is kind of the root of what I was saying, I don't know what a properly configured project is, I cloned their template, I followed the steps in their Readme and yet it just throws a main method not found, even right clicking Main() and running it still throws the same main could not be found method
2
u/nekokattt Extreme Brewer Nov 27 '20
Main()?
Is that a typo? It should be lower case and take
String[] argsas a sole parameter, contrary to C# where this is in capitals and the params are optional :)public class MyApp { public static void main(String[] args) { } }2
2
u/tawielden Nov 27 '20
This can also be caused by not structuring VM args properly in the environment. For example you have a a space where there shouldn't be one.
4
Nov 27 '20
As said before, your problem seems more like a setup one.
On the Android side, I can't help, like you, I have never been able to produce an app.
For the plugin, it might help if you share the repo so we can try ourselves.
1
u/TheScottishKreig Nov 27 '20
This is the repo I'm trying to work from https://github.com/runelite/plugin-hub
2
u/m1ss1ontomars2k4 Nov 27 '20
I am not really sure what instructions you are trying to follow, to be honest. I looked at another plugin and it also doesn't have a
mainmethod. This makes sense, since you are writing a plugin--it's a plugin for other software which has its ownmainmethod, so your code doesn't need one.You are basically writing a library. I don't think it needs a
mainmethod, and trying to run it makes no sense in the first place.1
u/TheScottishKreig Nov 27 '20
Sorry I should've clarified, the main method is within the test folder, it runs the runelite client and injects the plugin classes
2
u/anti_government Nov 27 '20
You've probably messed with the ide and sdk itself. The "main method not found" would only be there when you don't have a public class defining the main function to start from. Try starting a new project, and then import in the stuff you need for the plug-in.
2
u/TheScottishKreig Nov 27 '20
I suspected it might be a development environment thing so I've already tried removing old Java versions, fixing my path and reinstalling the IDE (clearing the settings and starting from fresh), as for manually importing I feel given I'm struggling just to get a template to run I'm probably not going to have any further luck doing it manually
1
u/wildjokers Nov 27 '20
What is the name of the game you are creating a plugin for? If you tell us we can try and give you some help.
1
u/TheScottishKreig Nov 27 '20 edited Nov 27 '20
Old-school runescape (specifically for the runelite client)
This is the repo, I've tried following both sets of instructions
1
u/nzayem Nov 27 '20
If you have copied the code and pasted it without modifying it, most likely you have now different public class name than the java file name.
The public class name should be always the same name of the Java file. IntelliJ will underline the tab name in red when the java file name and the public class name are different.
1
u/TheScottishKreig Nov 27 '20
I generated it from an example repo and didn't make any code changes
1
u/AreTheseMyFeet Nov 27 '20
didn't make any code changes
Does that include steps 7-10 (under "Using the template repository") from the plugin template repo readme?
From a quick glance seems like thePluginDescriptorandrunelite-plugin.propertiesfiles are how you set your plugin "active".
The first to define/name your plugin, the second to load it. Maybe the default values aren't defined completely/correctly? (I didn't clone it myself to test)1
u/TheScottishKreig Nov 27 '20
I got stuck at step 6 when trying to run the test
1
u/AreTheseMyFeet Nov 27 '20
There are two "create new plugin" choices ("Using the template repository" & "Using the script"), which one did you try or did you attempt both?
1
u/TheScottishKreig Nov 27 '20
I've attempted both. I asked in the dev channel for the discord related to it and ended up identifying that it's an environment issue (I can load it on a second pc with no issues) but I'm no closer to figuring out exactly what the issue is on that one pc
1
u/AreTheseMyFeet Nov 27 '20
If you know it's an environment problem then that cuts down the possible causes somewhat.
What version of java are you using? What version does the plugin/game require?
Is the Java install available on your PATH system environment?
Is your IDE using your system Java or it's own bundled Java?
^ Same question for gradle. Your own system installation or your IDE's built in?Do you also have python3 installed and available? The second plugin create method requires it so maybe the game/plugin engine does also.
1
u/TheScottishKreig Nov 27 '20
Same version on both machines, latest version of jdk 11. Java is in path (correct version too), ide is intellij pointed at my specific jdk folder. Not sure about grade will check that. And yeah I've got python3
1
u/PolyDigga Nov 27 '20
I started writing an app recently using Android Studio. I haven't had any real java experience either and I also come from a python background.
The tutorial that helped me get started (I was quite overwhelmed by all these xmls) was this one: https://youtu.be/Ob4vSoWud9k Not even the full one, I got a good idea of what I was doing after the first two or three vids. Now, this is not to say I am an expert or that I am producing high-quality apps, but I managed to build a couple of working apks by now. Reading data, writing data, making nice popups, it's all pretty simple actually as soon as you see behind the curtain. Also good to mention that for almost every issue you will encounter, type it into google, add 'android studio' to the front and you will find someone on SO who had that problem already.
1
1
u/dionthorn this.isAPro=false; this.helping=true; Nov 27 '20
I have an open source JavaFX based Game Project that you can clone/fork/mess with all you want if you need some practice. Learning how to setup maven in intellji might be helpful too. You can scope my pom.xml to see what maven plugins I use.
•
u/AutoModerator Nov 26 '20
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.