Thank you all for your answers and time!
Hello,
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.
Preferences.class (from where I call the method):
Preference sorted = (Preference) findPreference("sortPref");
sorted.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
Object d = new Dmarks();
((Dmarks) d).queryBookmarks();
return true;
}
});
the Dmarks.class method I call:
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 Dmarks.class
}
The Logcat:
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.droidil.droidmarks.Dmarks.queryBookmarks(
Dmarks.java:101)
E/AndroidRuntime(11718): at com.droidil.droidmarks.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.droidil.droidmarks/.Pre
ferences
Appreciate any help! :)
EDIT: I can't make queryBookmarks() a static function because it uses Android function managedQuery which is not a static function.