Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple SharedPreferences in Android
    primarykey
    data
    text
    <p>I'm having a problem, and I already tried everything I found on this site, it's not helping, so I'm asking this question myself.</p> <p>my code is:</p> <pre><code>public class MyActivity extends Activity{ protected PositionSense positionSense; protected Preferences preferences; String IP; String ID; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); positionSense = new PositionSense(this, null); SharedPreferences settings = getSharedPreferences("preferences", 0); IP = settings.getString("ip", "http://192.168.1.3:8080/servlet"); ID = settings.getString("id", "USER"); } </code></pre> <p>Later on, I use these variables in a background running thread that contacts the servlet and sends some info (including position and ID of the user which is saved in preferences)</p> <p>I'm not posting all of that because I don't want to clog up the thread more than necessary (but if it is needed, I will post it all)</p> <p>In any case, it doesn't work and it gives me the following error log:</p> <pre><code>09-14 16:47:20.854: WARN/dalvikvm(552): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 09-14 16:47:20.884: ERROR/AndroidRuntime(552): FATAL EXCEPTION: main java.lang.IllegalStateException: Could not execute method of the activity at android.view.View$1.onClick(View.java:3044) at android.view.View.performClick(View.java:3511) at android.view.View$PerformClick.run(View.java:14105) at android.os.Handler.handleCallback(Handler.java:605) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at android.view.View$1.onClick(View.java:3039) ... 11 more Caused by: java.lang.NullPointerException at com.moodswings.MoodSwingsActivity.clickHappy(MoodSwingsActivity.java:94) ... 14 more </code></pre> <p>I don't know what to do about it.</p> <p>Can someone give me the SIMPLEST possible way to save 2 strings in preferences in one activity that are used in some other activity within the same application? It's supposed to be really simple, but I simply cannot make it work, and I'm nearing my deadline. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload