Create a static method return the instance of your main class. Here's an example: Code (Text): private static Main i; public static Main get() { return i; } public void onEnable(){ Main.i = this; }
A few more Java tutorials may be helpful for you. What exactly are you trying to achieve? I sense an X, Y problem here.
If you had enough knowledge, would this thread exist? There a few different ways to achieve this. What I'm asking is What exactly are you trying to do? An X, Y problem is when you're asking about X but are trying to do Y. We're solving X for you when Y is the actual problem we all could have been solving in the first place.
These should help you quite a bit: Java tutorial home: https://docs.oracle.com/javase/tutorial/ Constructors: https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html Objects and classes: https://docs.oracle.com/javase/tutorial/java/javaOO/ Creating instances of classes: https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html
You can use this but is more work but it looks more clean in your code and more good: Code (Text): //In first class String ex; public String GetEx(){ return ex; } //In second class FirstClass first = new FirstClass(); String ex = first.GetEx(); You decide what to use.
Yes, that's one solution to a problem. The question is; is it the problem of this thread? The Main class is usually static. Means it won't work. There's also static classes, Singletons, and the Service Locator pattern. I'm hesitant to recommend any at this point since I don't know what the problem actually is. It may be that none of those are even required for this particular issue.
Ok you can to use : public FistClass fistclass; public secondclass(FistClass fc){ fistclass = fc; } fistclass.Get...
That is indeed another solution to a problem. I wouldn't recommend that one in particular for this discussion, however, as it will end in spaghetti code.
Ayy, look at that. An indicator of delicious pasghetti. Without code or an idea of what you're trying to achieve, it's hard to say much. The fact that you've given us the name of one class and nothing else doesn't help, either. Make sure you're setting warpString before you access it.
You're setting a String equal to an empty string. Then complaining when it's sending as an empty message. See the logic problem here?
The part that's confusing me is the "console it debugs as non empty" Define "non empty". What's it supposed to read?
Somewhere in your code that string is being set to empty. Find out where. I would also recommend the use of a design pattern to help eliminate some of your spaghetti code.
Using dependency injection will generally not end up in spaghetti code @TheBlackTeddy don't depend on static as an access modifier, it's not designed to be one (Instead, it's a memory tool)