0

having error for getting into next intent.

When I click on the button, it gave me a force close immediately. I wanted to parse the bundle into the summary onclick method.

logcat

01-27 22:17:11.826: E/AndroidRuntime(32003): FATAL EXCEPTION: main
01-27 22:17:11.826: E/AndroidRuntime(32003): java.lang.IllegalStateException: Could not find a method summaryClick(View) in the activity class com.example.fuellogproject.ViewAll for onClick handler on view class android.widget.Button with id 'summaryBTN'
01-27 22:17:11.826: E/AndroidRuntime(32003):    at android.view.View$1.onClick(View.java:3711)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at android.view.View.performClick(View.java:4261)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at android.view.View$PerformClick.run(View.java:17356)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at android.os.Handler.handleCallback(Handler.java:615)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at android.os.Looper.loop(Looper.java:137)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at android.app.ActivityThread.main(ActivityThread.java:4921)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at java.lang.reflect.Method.invokeNative(Native Method)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at java.lang.reflect.Method.invoke(Method.java:511)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at dalvik.system.NativeStart.main(Native Method)
01-27 22:17:11.826: E/AndroidRuntime(32003): Caused by: java.lang.NoSuchMethodException: summaryClick [class android.view.View]
01-27 22:17:11.826: E/AndroidRuntime(32003):    at java.lang.Class.getConstructorOrMethod(Class.java:460)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at java.lang.Class.getMethod(Class.java:915)
01-27 22:17:11.826: E/AndroidRuntime(32003):    at android.view.View$1.onClick(View.java:3704)
01-27 22:17:11.826: E/AndroidRuntime(32003):    ... 11 more

code:

public void summaryClick (int arg2)
    {
        Intent sum = new Intent(this, summary.class);
        fuelLogPojo clickedObject = pojoArrayList.get(arg2);
        Bundle dataBundle = new Bundle();
        dataBundle.putString("clickedID", clickedObject.getid());
        dataBundle.putString("clickedDate", clickedObject.getdate());
        dataBundle.putString("clickedPrice", clickedObject.getprice());
        dataBundle.putString("clickedPump", clickedObject.getpump());
        dataBundle.putString("clickedCost", clickedObject.getcost());
        dataBundle.putString("clickedOdometer", clickedObject.getodometer());
        dataBundle.putString("clickedpreOdometer",
                clickedObject.getpreodometer());
        dataBundle.putString("clickedFCon", clickedObject.getfcon());
        Log.i("FuelLog", "dataBundle " + dataBundle);
        // Attach the bundled data to the intent
        sum.putExtras(dataBundle);

        // Start the Activity
        startActivity(sum);


    }
manlio
  • 18,345
  • 14
  • 76
  • 126
Chloe
  • 149
  • 1
  • 12

2 Answers2

4

Your method must have the signature indicated in the error message. So change the signature to:

public void summaryClick(View view)
Ben Weiss
  • 17,182
  • 6
  • 67
  • 87
4

Your method signature is wrong

Change

 public void summaryClick (int arg2)

to

 public void summaryClick (View arg2)

You probably have

 andorid:onClick="summaryClick" 

in xml for button

To the comment

 fuelLogPojo clickedObject = pojoArrayList.get(arg2);

View arg2 is not int.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • I will get prompt error on fuelLogPojo clickedObject = pojoArrayList.get(arg2); – Chloe Jan 27 '14 at 14:22
  • it will as whether to make .get(arg2) as int – Chloe Jan 27 '14 at 14:23
  • 1
    `fuelLogPojo clickedObject = pojoArrayList.get(arg2);` this is the problem. `View arg2` is not `int` – Raghunandan Jan 27 '14 at 14:23
  • @Chloe try `pojoArrayList.get(0);` it will work. you need to decide how you want to get items from list based on index for which we do not have enough info – Raghunandan Jan 27 '14 at 14:27
  • examaple? i don't get u – Chloe Jan 27 '14 at 14:27
  • @Chloe what is the item that you want to get from list. index starts 0 to the size-1. which item do you need. on what condition that is for you to decide – Raghunandan Jan 27 '14 at 14:29
  • I've try your method, it works. However, if I have 3 items in my listview,when I click on summary, it only shows me one item in the log – Chloe Jan 27 '14 at 14:31
  • @Chloe did you read my previous comment index 0 is always first item. Its for you to decide what logic or on what condition you want to get list item. – Raghunandan Jan 27 '14 at 14:33
  • what if I want to get all the item? – Chloe Jan 27 '14 at 14:34
  • use a for loop i=0 to list.size-1 and then use `pojoArrayList.get(i)`. Further questions ask a new question with relevant details – Raghunandan Jan 27 '14 at 14:35
  • my new question http://stackoverflow.com/questions/21383772/passing-a-list-of-data-from-one-intent-to-another – Chloe Jan 27 '14 at 14:45