I'm working on a piece of code that is a settings activity for an app 
widget. Right now I have the code set up that if takes the saved value of 
the number and enters it into the text view of another activity via shared 
settings. The issue I am running into is that when press the load button it 
fires an NPE at me on the given line of code which is: Line 48 
AKA: dataResults.setText(dataReturned); I will post the whole code for this 
setting as well as its related logcat below:

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class WWSettings extends Activity implements OnClickListener {

EditText sharedData;
Context c;
TextView dataResults;
public static String filename = "sharedString";
SharedPreferences someData;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.widgetconfig);
Button b = (Button) findViewById(R.id.btnwidgetconfig);
Button b1 = (Button) findViewById(R.id.loadBtnWidgetConfig);
c = WWSettings.this;
b.setOnClickListener(this);
b1.setOnClickListener(this);
sharedData = (EditText)findViewById(R.id.etwidgitconfig);
dataResults = (TextView)findViewById(R.id.userNum);
someData = getSharedPreferences(filename, 0);
}

public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.btnwidgetconfig:
String stringData = sharedData.getText().toString();
SharedPreferences.Editor editor = someData.edit();
editor.putString("sharedString", stringData);
editor.commit();
break;
case R.id.loadBtnWidgetConfig:
someData = getSharedPreferences(filename, 0);
String dataReturned = someData.getString("sharedString", "Can't 
Load....Sorry!");
dataResults.setText(dataReturned);
break;
}
}
}

And the logcat:

07-29 08:42:00.360: E/AndroidRuntime(9249): FATAL EXCEPTION: main
07-29 08:42:00.360: E/AndroidRuntime(9249): java.lang.NullPointerException
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
lionsimage.com.onClick(Settings.java:48)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
android.view.View.performClick(View.java:2485)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
android.view.View$PerformClick.run(View.java:9080)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
android.os.Handler.handleCallback(Handler.java:587)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
android.os.Handler.dispatchMessage(Handler.java:92)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
android.os.Looper.loop(Looper.java:130)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
android.app.ActivityThread.main(ActivityThread.java:3683)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
java.lang.reflect.Method.invokeNative(Native Method)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
java.lang.reflect.Method.invoke(Method.java:507)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
07-29 08:42:00.360: E/AndroidRuntime(9249): at 
dalvik.system.NativeStart.main(Native Method)

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to