Note that there are some explanatory texts on larger screens.

plurals
  1. POApp keeps on crashing
    primarykey
    data
    text
    <p>I've got all of my code now but keeps on crashing. Basically, the code is a button that, when clicked, will add a number to an amount. So, when clicked once, it will be 1; clicked again will become 2, then 3, and so on like a ticker. </p> <pre><code>package com.example.counter; import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; public class MainActivity extends Activity { // Private member field to keep track of the count private int mCount = 0; public static final String PREFS_NAME = "com.example.myApp.mCount"; private SharedPreferences settings = null; private SharedPreferences.Editor editor = null; /** ADD THIS METHOD **/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Always call the superclass method first settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE); } @Override public void onPause() { super.onPause(); // Always call the superclass method first mCount = settings.getInt("mCount", 0); } @Override public void onResume() { super.onResume(); // Always call the superclass method first editor = settings.edit(); /** ADD THIS LINE **/ editor.putInt("mCount", mCount); editor.commit(); } } </code></pre> <p>xml:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" &gt; &lt;TextView android:id="@+id/TextViewCount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" /&gt; &lt;Button android:id="@+id/ButtonCount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/TextViewCount" android:layout_alignRight="@+id/TextViewCount" android:layout_marginBottom="22dp" android:text="Count" /&gt; &lt;/RelativeLayout&gt; </code></pre>
    singulars
    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