Call non-static method (located in main class) from different class
<p><strong>Thank you all for your answers and time!</strong></p>

<p>Hello,</p>

<p>I've been trying to call a non-static method, located in my main application Class, from the Preferences Class.
Because the method I call is not static, I instantiate the main class and then try to call the specific method I want but it's force closing.</p>

<p><strong>Preferences.class (from where I call the method):</strong></p>

<pre><code>Preference sorted = (Preference) findPreference("sortPref");
        sorted.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Object d = new mainActivity();
                ((mainActivity) d).queryBookmarks();

                return true;
            }
        });
</code></pre>

<p><strong>the mainActivity.class method I call:</strong></p>

<pre><code>    public void queryBookmarks() {

        Toast.makeText(context, "blah blah", Toast.LENGTH_LONG).show(); 
//context is not null and the Toast is working if I  call it from mainActivity.class

        }
</code></pre>

<p><strong>The Logcat:</strong></p>

<pre><code>E/AndroidRuntime(11718): FATAL EXCEPTION: main
E/AndroidRuntime(11718): java.lang.NullPointerException
E/AndroidRuntime(11718):        at android.content.ContextWrapper.getContentReso
lver(ContextWrapper.java:90)
E/AndroidRuntime(11718):        at android.app.Activity.managedQuery(Activity.ja
va:1520)
E/AndroidRuntime(11718):        at com.queryBookmarks(
.java:101)
E/AndroidRuntime(11718):        at com.Preferences$2.onPrefer
enceChange(Preferences.java:47)
E/AndroidRuntime(11718):        at android.preference.Preference.callChangeListe
ner(Preference.java:756)
E/AndroidRuntime(11718):        at android.preference.ListPreference.onDialogClo
sed(ListPreference.java:219)
E/AndroidRuntime(11718):        at android.preference.DialogPreference.onDismiss
(DialogPreference.java:384)
E/AndroidRuntime(11718):        at android.app.Dialog$ListenersHandler.handleMes
sage(Dialog.java:1047)
E/AndroidRuntime(11718):        at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime(11718):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(11718):        at android.app.ActivityThread.main(ActivityThrea
d.java:4627)
E/AndroidRuntime(11718):        at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime(11718):        at java.lang.reflect.Method.invoke(Method.java:5
21)
E/AndroidRuntime(11718):        at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(11718):        at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:626)
E/AndroidRuntime(11718):        at dalvik.system.NativeStart.main(Native Method)

D/dalvikvm(11718): GC_FOR_MALLOC freed 4248 objects / 282248 bytes in 40ms
W/ActivityManager(  244):   Force finishing activity com.package/.Pre
ferences
</code></pre>

<p>Appreciate any help! :)</p>

<p>EDIT: I can't make queryBookmarks() a static function because it uses Android function managedQuery which is not a static function.</p>
