java - Illegal state exception onclick -


I am trying to retrieve data by clicking on a button in my activity. I have declared an onclick in activity_second. Here is my code. I am illegal Exception: The method can not be executed in the activity. What is wrong with my code? Why is Logcat invocationTargetException showing. In fact this error is and why is there NullPointerException ?? Public class enhances second activity activity (private edit text loadedInfo; personal button butn1; @ override protected zero; creature (bundle saved instainstate) {super.New (savedinstenstate); setContentView (R.layout.activity_second); Loadinfo = (EditText) findViewById (R.id.editText1); Butn1 = (button) findViewById (R.id.button1);} public void apurv1 (views) {file folder = getCacheDir (); File myfile = new file (folder, "mydata1.txt"); string data = readdata (File! = Null) {loadinfo.setText (data);} Else {loadinfo.setText ("no entry was done");}} Private string readability (file mifile) {FileInputStream fis = null Try {Fis = new FileInputStream (myfile);} Hold (FileNotFoundException E) {// TODO Auto generated blocking block e.printStackTrace ();} Int read = -1; stringbuffer stringbuffer = new stringbuffer (); try {While (read = fis.read ())! = - 1) {stringbuffer.append (read four));} return stringbuffer.toString (); } Grip (IOException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); } Finally {if (fis! = Null} {try {fis.close (}}} Grip (IOException e) {// TODO Auto-Generated Catch Block e.printStackTrace (); }}} Return tap; } @ Override Public Boolean On Crate Option Menu (Menu Menu) {// Enhancing Menu; It adds the item to the Action Bar if it exists GetMenuInflater (). Flood (R. menu.Second, menu); Back true; }}

StackTrace

  04-26 00: 59: 00.545: E / Android Random (2023): Fatal Exception: Main 04-26 00: 59: 00.545: E / Android Random (2023): java.lang.IllegalStateException: The method of operation could not be executed 04-26 00: 59: 00.545: E / Android Time (2023): Android. View.View $ 1.onClick (see .Java 3633) 04-26 00: 59: 00.545: E / Android Random (2023): On Android View.View.performClick (see.Java 4240) 04-26 00: 59: 00.545: E / Android Time (2023): On Android. View.View $ PerformClick.run (see: Java: 17721) 04-26 00: 59: 00.545: E / Android Random (2023): Callback (Handler. Java: 730) on Android.OS Handler Hourndle 04-26 00: 59: 00.545: E / Android Random (2023): Android.OS Hendlr Dispatch Message (Handlrkjawaः 9 2) 04-26 00: 59: 00,545 E / Androidrentaim (2023): Android on .os.Looper.loop (Looper.java:137) 04-26 00: 59: 00.545: E / Android Random (2023): Android. App ActivateTrade.Mine (ActivityTrad.JavaTT 103) 04-26 00:59: 00.545: E / Android Time (2023): at java.lang.reflect.Method.invokeNative (native method) 04-26 00: 59: 00.545: E / Android Rentaim (2023): on JavaklangkreflectkMethodkinvoke (Vidhikjawa 2525) 04-26 00: 59: 00,545 e / Androidrentaim (2023): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:737) 04-26 00: 59: 00.545: e / Android Runtime (2023): on com.android.internal.os.ZygoteInit.main (Jyogoitinitkjawa 53) 04-26 00 : 59: 00.545: E / Android Random (2023): Dlvic. System Netstartkmain (Basic Law) 04-26 00: 59: 00,545 was carried out by E / Androidrentaim (2023):: java.lang.reflect.InvocationTargetException 04-26 00: 59: 00.545: E / Androidrentaim (2023): At java.lang.reflect.Method.invokeNative (Basic Method) 04-26 00: 59: 00.545: E / Android Random (2023): at java.lang.reflect.Method.invoke (method.java.25) 04- 26 00: 59: 00.545: E / Android Random (2023): On Android. $ 1. Click Click (View. Java 3628) 04-26 00: 59: 00.545: E / Android Random (2023): ... 11 and 04-26 00: 59: 00.545: E / Android Random (2023): caused by: java.lang NullPointerException 04-26 00: 59: 00.545: e / Androidrentaim (202 3) on com.example.storageexternal.SecondActivity.readdata (SecondActivity.java:62) 04-26 00: 59: 00.545: E / AndroidRuntime (2023): com.example.storageexternal.SecondActivity.apurv1 (SecondActivity.java: 36) 04-26 00: 59: 00.545: E / Android Random (2023): ... 14 more  

Assume that activity_second is your XML file and your Pa If there is a button which is a feature for your button android: onClick = "readdate" , your redDate method should be returned by zero to the view argument, such as < / P>

  public void readdate (see V) {// add code}   

or via an OnClickListener

for more information Check out this post

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -