我必须调用我的函数来单击按钮。如果在 XML onclick 事件调用 (listaFatture) 中出现错误。为什么?我应该在另一个班级设置吗?
private void listaFatture(){
SQLiteDatabase db = new FattureHelper(this).getReadableDatabase();
final List<Dettaglio> dettagli = new ArrayList<Dettaglio>();
String sql ="SELECT nome_fornitore, SUM(importo_fattura) FROM Fatture WHERE importo_fattura>0 GROUP BY nome_fornitore";
Cursor c = db.rawQuery(sql, null);
while (c.moveToNext()){
Dettaglio d = new Dettaglio();
d.fornitore = c.getString(0);
d.totale = c.getFloat(1);
dettagli.add(d);
}
c.close();
db.close();
ListAdapter adapter = new ArrayAdapter<Dettaglio>(this, R.layout.dettaglio_elenco_fatture_group, R.id.t_fornitore_group, dettagli){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
TextView tvFornitore, tvTotale;
tvFornitore = (TextView) row.findViewById(R.id.t_fornitore_group);
tvTotale = (TextView) row.findViewById(R.id.t_euro_group);
Dettaglio d = dettagli.get(position);
tvFornitore.setText(d.fornitore+"");
日志猫:
09-21 15:29:09.617: E/AndroidRuntime(20670): java.lang.IllegalStateException: Could not find a method listaFatture()(View) in the activity class fatture.acquisti.Elenco_fatt_group for onClick handler on view class android.widget.Button with id 'button_1'
09-21 15:29:09.617: E/AndroidRuntime(20670): at android.view.View$1.onClick(View.java:3722)
09-21 15:29:09.617: E/AndroidRuntime(20670): at android.view.View.performClick(View.java:4354)
09-21 15:29:09.617: E/AndroidRuntime(20670): at android.view.View$PerformClick.run(View.java:17961)
09-21 15:29:09.617: E/AndroidRuntime(20670): at android.os.Handler.handleCallback(Handler.java:725)
09-21 15:29:09.617: E/AndroidRuntime(20670): at android.os.Handler.dispatchMessage(Handler.java:92)
09-21 15:29:09.617: E/AndroidRuntime(20670): at android.os.Looper.loop(Looper.java:137)
09-21 15:29:09.617: E/AndroidRuntime(20670): at android.app.ActivityThread.main(ActivityThread.java:5328)
09-21 15:29:09.617: E/AndroidRuntime(20670): at java.lang.reflect.Method.invokeNative(Native Method)
09-21 15:29:09.617: E/AndroidRuntime(20670): at java.lang.reflect.Method.invoke(Method.java:511)
09-21 15:29:09.617: E/AndroidRuntime(20670): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
09-21 15:29:09.617: E/AndroidRuntime(20670): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
09-21 15:29:09.617: E/AndroidRuntime(20670): at dalvik.system.NativeStart.main(Native Method)
09-21 15:29:09.617: E/AndroidRuntime(20670): Caused by: java.lang.NoSuchMethodException: listaFatture() [class android.view.View]
09-21 15:29:09.617: E/AndroidRuntime(20670): at java.lang.Class.getConstructorOrMethod(Class.java:460)
09-21 15:29:09.617: E/AndroidRuntime(20670): at java.lang.Class.getMethod(Class.java:915)
09-21 15:29:09.617: E/AndroidRuntime(20670): at android.view.View$1.onClick(View.java:3715)