Persistant Data (Int Java)
<p>I'm trying to get this app to work, but for some reason the onCreate method always causes a huge fuss. If I comment out lines 29-55 it works, but of course no persistent data. I'm sure this is likely a simple &amp; stupid mistake, so any quick help is appreciated greatly!</p>

<pre><code>import java.text.DecimalFormat;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity 
{

int day = 0;
int cig = 0;
int cigTotal;
double average = 0.0;


@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SharedPreferences prefs = getSharedPreferences("yep", Activity.MODE_PRIVATE);
    //Start of error
    EditText today = (EditText) findViewById(R.id.todayValue);
    EditText days = (EditText) findViewById(R.id.daysValue);
    EditText total = (EditText) findViewById(R.id.totalValue);

    int todayV = prefs.getInt("today", 0);
    int daysV = prefs.getInt("days", 0);
    int totalV = prefs.getInt("total", 0);

    today.setText(todayV);
    days.setText(daysV);
    total.setText(totalV);
    //End of error
}

@Override
public boolean onCreateOptionsMenu(Menu menu) 
{

    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) 
{
    SharedPreferences prefs = getSharedPreferences("a_prefs_name", Activity.MODE_PRIVATE);      
    SharedPreferences.Editor editor = prefs.edit();
    String initial="0";
    String iaverage="0.00";

    // Handle item selection
    switch (item.getItemId()) 
    {
        case R.id.menu_reset:
            editor.putInt("today", 0);
            editor.putInt("days", 0);
            editor.putInt("total", 0);
            editor.commit();

            final EditText todayReset = (EditText) findViewById(R.id.todayValue);
            todayReset.setText(initial);
            final EditText dayReset = (EditText) findViewById(R.id.daysValue);
            dayReset.setText(initial);
            final EditText totalReset = (EditText) findViewById(R.id.totalValue);
            totalReset.setText(initial);
            final EditText averageReset = (EditText) findViewById(R.id.avgValue);
            averageReset.setText(iaverage); 

            return true;

        case R.id.menu_new_day:
            DecimalFormat df = new DecimalFormat("#0.00");
            cigTotal += cig;
            day++;
            EditText countDays = (EditText) findViewById(R.id.daysValue);
            countDays.setText("" + day);
            EditText tallyCigs = (EditText) findViewById(R.id.totalValue);
            tallyCigs.setText("" + cigTotal);
            cig = 0;
            EditText countCig = (EditText) findViewById(R.id.todayValue);
            countCig.setText("" + cig);

            average = ((double)cigTotal/(double)day);
            EditText averageView = (EditText) findViewById(R.id.avgValue);
            averageView.setText("" + df.format(average));

            editor.putInt("today", cig);
            editor.putInt("days", day);
            editor.putInt("total", cigTotal);

            editor.commit();

    default:
        return super.onOptionsItemSelected(item);
    }
}

public void clickSmokedOne(View view) 
{
    cig++;
    EditText countCig = (EditText) findViewById(R.id.todayValue);
    countCig.setText("" + cig); 
}

@Override
public void onPause() 
{
    super.onPause();

    final EditText today = (EditText) findViewById(R.id.todayValue);
    final EditText days = (EditText) findViewById(R.id.daysValue);
    final EditText total = (EditText) findViewById(R.id.totalValue);

    int todayText = Integer.parseInt(today.getText().toString());
    int daysText = Integer.parseInt(days.getText().toString());
    int totalText = Integer.parseInt(total.getText().toString());

    SharedPreferences prefs = getSharedPreferences("yep", Activity.MODE_PRIVATE);
    Editor editor = prefs.edit();
    editor.putInt("today", todayText);
    editor.putInt("days", daysText);
    editor.putInt("total", totalText);
    editor.commit();

}       
</code></pre>

<p>}</p>
