0

First thing first; I understand that it is not possible to call a non-static method from a static method as detailed here.

Q: I was wondering if I can set the string (non-static) as static with a constructor method so that I can pass the string staticly across java classes and to JNI:

Intent myIntent = new Intent(Intent.ACTION_VIEW);
   String argument = "iqsrc://"+ arguments.getText().toString();
   Uri myUri = Uri.parse(argument);
   myIntent.setData(myUri);
   startActivity(myIntent);

String arguments = new argument
//Used to pass static string to /from java

and will every time the non-static string changes a new static value be changing as well?

1 Answer 1

2

First thing first; I understand that it is not possible to call a static method from a non-static method

First things first, you can call a static method from a non-static method. You can't call a non-static method from a static method.

You can set a static variable from a non-static method if that is your intention:

static String foo;

void myNonStaticMethod() {
    foo = "bar";
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you...sorry for the dyslexia.
Ähemm ... it is news for me that one alledgedly cannot call non-static methods from static ones? After all, main is a static method, and from there it all begins. If it were as you said, no non-static method could ever be get called.
@Ingo I think we're talking semantics here. You can not call a non-static method without calling on an instance., eg new MyClass().myNonStaticMethod();, but not just myNonStaticMethod(); on its own.
@Bohemian Calling a non-static method is, of course, by definition always using a receiver, even if you don't need to write it explicitly when the receiver is supposed to be this. Hence, we can say there is basically only one way to call non-static methods. Anyway, stating that one cannot call non-static methods from static ones is simply wrong. It is just that you can't use this, because there is none.

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.