First, clean your project (Project > Clean from Eclipse main menu, or ant clean from the command line). Then rebuild and try again. Sometimes, the R values get a bit out of sync with other precompiled Java code, and cleaning the project clears that up.
If the error persists, then apparently res/layout/widgetconfig.xml does not have a widget named @+id/userNum, which is why dataResults would be null. On Sun, Jul 29, 2012 at 8:50 AM, Cythes <[email protected]> wrote: > 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 [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 3.8 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

