android - Strange exception on a button -


So, I want to save a file while typing in a file, however, I have FC, here's the code :

  Find the last button button = (button) VVBIID (RID button); Button.setOnClickListener (New View.OnClickListener) {Public Zero onClick (see v) {String value 1 = vol.getText () toString (); .. String value 2 = kil.getText () toString ();; Value1 = zero and amp; value1.trim () Length ()> 0 & amp; amp; amp; value2! = Null & amp; value2.trim (). Length ()> 0 ) {Float q1 = Float.parseFloat wall.gate text (.) ToString ()); Float q2 = float.parseflowat (kil.gettext (.) ToString ()); Float x = ((q1 / q2) * 100); String y = float.stostring (x;); Data = data + ":" + + + "L / 100 km \ n" + value1 + "liters" + value2 + "km \ n"; Shared Priorities Preferences = Preference Manager. Gate default shared reference (reference); If (Data! = "") {String file name = matching resource (). GetString (R.string.name ()); String file diar = "+ + preferences.getString (" Login "," ") +" "+ Preferences.getString (" Mark "," ") +" "MyIOkWriteSettings (reference, fileDir + fileName, data); data =" ";}} e Lse {toast.makeText (carburant.this," Veulijh vÃÆ'à  a € ™ Ã⠀,  · Riffer Les Deux Champs "toast. Elananacti_eloji). show () log;: 03-16 20: 52: 59.080: error / Android Rentaim (101 9): fatal exception: main 03-16 20: 52: 59.080: error / AndroidRuntime (1019): java.lang.NullPointerException 03-16 20: 52: 59.080: 03-16 error / AndroidRuntime (1019): android.preference.PreferenceManager.getDefaultSharedPreferencesName (PreferenceManager.java:353) 20: 52: 59.080: Error / AndroidRuntime (1019): android.preference.PreferenceManager.getDefaultSharedPreferences (PreferenceManager.java:348) 03-16 20: 52: 59.080: Error / AndroidRuntime (1019): at carburant.android.com .comburant $ 1.onClick (carburant.java:118) 03-16 20:52: 59.080: Error / AndroidRuntime (1019): Android. View.View.performClick ( See.Java 2485) 03-16 20:52: 59.080: Error / AndroidRuntime (1019): android.view.View $ PerformClick.run (View.java:9080) on 03-16 20:52: 59.080: Error / AndroidRuntime (1019): on AndroidkoskHandlerkhandleCallback (Handlrkjawa Liidyusn) 03-16 20: 52: 59.080: error / Androidrentaim (101 9): Androidkoskhandlr Dispatch Message (Handlrkjawaः 92) 03 16 20: 52: 59.080: Error / Android Random (101 9): Android. On Los Looper Loop (Looper.java:123) 03-16 20:52: 59.080: Error / AndroidRuntime (1019): app.ActivityThread.main on Android (ActivityThread.java:3683) 03-16 20:52: 59.080: Error / AndroidRuntime (1019): java.lang.reflect.Method.invokeNative (Native Method) 03-16 at 20: 52: 59.080: Error / Android Runtime (1019): at java.lang.reflect.Method.invoke (method Java: 507) 03-16 20: 52: 59.080: Error / AndroidTime (1019): at com.android.internal.os. ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:839) 03-16 20: 52: 59.080: 03-16 Error / AndroidRuntime (1019): com.android.internal.os.ZygoteInit.main (ZygoteInit.java:597) 20: 52: 59.080: error / Android runtime (101 9): Dalvik.system.NativeStart.main (the original method) 03-16 20: 52: 59.080: Warning / activity Manager (68): Forising Finishing activity carburant.android .com / .carburant 03-16 20:52: 59.854: Alert / Activity Manager (68): Activity Stop For Pausing Rock {406e89b8 carburant.android.com/.carburant}  

Any help please ? Thanks :).

According to your stack trace and additional information, the error is a null pointer line

  Shared Priorities = Preference Manager .get Defaults Shared References (Reference);   

I suspect that the reference parameter is zero. Is context a variable name that you have already declared and assigned a message?

Edit:

You must specify a reference in your reference variable. By declaring this as a global variable, it makes it zero.

Please try it:

  Private context reference = getApplicationContext ();    

Comments