0

I currently have two constructors in one of my classes, one going to my main class, and the other to another class that has most of the methods that I use. The reason I don't use static methods for my second class that I have a constructor, is that I don't want the code to be used by any other source, just mine. Here are the two constructors:

PrisonProfessionalMain plugin;

public PPCommandAdminMenu(PrisonProfessionalMain instance)
{
    plugin = instance;
}

QuickMethods qm;
public PPCommandAdminMenu(QuickMethods instance)
{
    qm = instance;
}

Then I am calling a method from the QuickMethods class here:

qm.getConfigString(plugin, "prefix")

Apparently, whatever method I call from this class it returns null. I do not think it is what I put inside of the method, but here is the method from the other class:

public String getConfigString(PrisonProfessionalMain instance, String configvar)
{
    return colorize(instance.getConfig().getString(configvar));
}

I don't see a problem here, but I am wondering if I should use a static way instead. I want to try and stay away from static methods for the reason I stated above.

REMEMBER: Calling any other method from this class results in it returning null. I know this because in console it has a stack trace that reads it null. It says this on the line that is calling any method from this class.

I tried removing the Strings and instances from inside the method:

public String getConfigString()
{
    return System.out.println("test");
}

This still however, resulted in another null pointer, pointing at the line that I called the method on.

My question is: How would I have the QuickMethods class stop returning null upon calling methods/strings from it.

2
  • Your question is not clear. Commented May 8, 2015 at 2:12
  • @DoNhuVy better now? Commented May 8, 2015 at 2:15

1 Answer 1

3

Only one constructor can be called at a time, given your code it appears you need to combine your constructors like,

QuickMethods qm;
PrisonProfessionalMain plugin;
public PPCommandAdminMenu(PrisonProfessionalMain plugin, QuickMethods qm)
{
    this.plugin = plugin;
    this.qm = qm;
}

Otherwise (by definition) one will be null.

Also,

public String getConfigString()
{
    return System.out.println("test");
}

isn't legal code because PrintStream.println() is void (and System.out is a PrintStream). You can use something like

String str = "test";
System.out.println(str);
return str;
Sign up to request clarification or add additional context in comments.

2 Comments

How would I make QuickMethods a variable in my main class to be with the constructor when registering the class with the constructor.
@JarFile By creating an instance of QuickMethods? QuickMethods qmInstance = new QuickMethods(); would create a reference to an instance of QuickMethods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.