Note that there are some explanatory texts on larger screens.

plurals
  1. POSharedPreferences getting "Could not execute method of the Acitvity"
    text
    copied!<p>I want to store user data and a password, but I always get an error "Could not execute method of the activity".</p> <p>I think the write actions works:</p> <pre><code>Editor editor = getSharedPreferences("pref", 0).edit(); editor.putString(CustomizedListView.KEY_USER, username); editor.putString(CustomizedListView.KEY_PASSWORD, password); System.out.println("username: " + username); System.out.println("password: " + password); editor.commit(); </code></pre> <p>I get an error with reading the preferences:</p> <pre><code>public class RESTClient extends Activity { private ArrayList&lt;NameValuePair&gt; uebergabeParam = new ArrayList&lt;NameValuePair&gt;(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } public String getResponse(String URLParameter, HttpMethod method) { System.out.println("RESTClient"); SharedPreferences pref = getPreferences(MODE_PRIVATE); // or SharedPreferences pref = getSharedPreferences("pref", MODE_PRIVATE); String username = pref.getString(CustomizedListView.KEY_USER, ""); String password = pref.getString(CustomizedListView.KEY_PASSWORD, ""); try { Client client = new Client(); client.addParameter(method, uebergabeParam, URLParameter, username , password); return client.execute().get(); } catch (InterruptedException e) { System.out.println("RESTClient getResponse " + e); e.printStackTrace(); } catch (ExecutionException e) { System.out.println("RESTClient getResponse " + e); e.printStackTrace(); } return ""; } } </code></pre> <p>I get the following error:</p> <pre><code>02-22 17:37:58.903: I/System.out(1714): RESTClient 02-22 17:37:58.903: D/AndroidRuntime(1714): Shutting down VM 02-22 17:37:58.903: W/dalvikvm(1714): threadid=1: thread exiting with uncaught exception (group=0x412f42a0) 02-22 17:37:58.918: E/AndroidRuntime(1714): FATAL EXCEPTION: main 02-22 17:37:58.918: E/AndroidRuntime(1714): java.lang.IllegalStateException: Could not execute method of the activity 02-22 17:37:58.918: E/AndroidRuntime(1714): at android.view.View$1.onClick(View.java:3691) 02-22 17:37:58.918: E/AndroidRuntime(1714): at android.view.View.performClick(View.java:4211) 02-22 17:37:58.918: E/AndroidRuntime(1714): at android.view.View$PerformClick.run(View.java:17267) 02-22 17:37:58.918: E/AndroidRuntime(1714): at android.os.Handler.handleCallback(Handler.java:615) 02-22 17:37:58.918: E/AndroidRuntime(1714): at android.os.Handler.dispatchMessage(Handler.java:92) 02-22 17:37:58.918: E/AndroidRuntime(1714): at android.os.Looper.loop(Looper.java:137) 02-22 17:37:58.918: E/AndroidRuntime(1714): at android.app.ActivityThread.main(ActivityThread.java:4898) 02-22 17:37:58.918: E/AndroidRuntime(1714): at java.lang.reflect.Method.invokeNative(Native Method) 02-22 17:37:58.918: E/AndroidRuntime(1714): at java.lang.reflect.Method.invoke(Method.java:511) 02-22 17:37:58.918: E/AndroidRuntime(1714): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 02-22 17:37:58.918: E/AndroidRuntime(1714): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 02-22 17:37:58.918: E/AndroidRuntime(1714): at dalvik.system.NativeStart.main(Native Method) 02-22 17:37:58.918: E/AndroidRuntime(1714): Caused by: java.lang.reflect.InvocationTargetException 02-22 17:37:58.918: E/AndroidRuntime(1714): at java.lang.reflect.Method.invokeNative(Native Method) 02-22 17:37:58.918: E/AndroidRuntime(1714): at java.lang.reflect.Method.invoke(Method.java:511) 02-22 17:37:58.918: E/AndroidRuntime(1714): at android.view.View$1.onClick(View.java:3686) 02-22 17:37:58.918: E/AndroidRuntime(1714): ... 11 more 02-22 17:37:58.918: E/AndroidRuntime(1714): Caused by: java.lang.NullPointerException 02-22 17:37:58.918: E/AndroidRuntime(1714): at android.app.Activity.getLocalClassName(Activity.java:4556) 02-22 17:37:58.918: E/AndroidRuntime(1714): at android.app.Activity.getPreferences(Activity.java:4589) 02-22 17:37:58.918: E/AndroidRuntime(1714): at kommunikation.RESTClient.getResponse(RESTClient.java:67) 02-22 17:37:58.918: E/AndroidRuntime(1714): at Login.onClick(Login.java:124) 02-22 17:37:58.918: E/AndroidRuntime(1714): ... 14 more </code></pre> <p>Hope you can help I don't know why. Thank a lot!</p> <p><strong>EDIT:</strong></p> <pre><code>public class CustomizedListView extends Activity { // Login public static final String KEY_USER = "user"; public static final String KEY_PASSWORD = "password"; } </code></pre> <p>I edited the getReponse() method too and added the </p> <blockquote> <p>super.onCreate(savedInstanceState);</p> </blockquote>
 

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