错误:数据库类中的方法 cleanCart 无法应用于给定类型

在做一个食品应用程序项目时,我的 cleanCart() 方法遇到了问题。这是我的堆栈跟踪:


error: method cleanCart in class Database cannot be applied to given types;

                new Database(getBaseContext()).cleanCart();

                                              ^

  required: Order

  found: no arguments

  reason: actual and formal argument lists differ in length

Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

1 error


FAILURE: Build failed with an exception.


* What went wrong:

Execution failed for task ':app:compileDebugJavaWithJavac'.

> Compilation failed; see the compiler error output for details.

这是我的 Cart.java 类


private void showAlertDialogue() {


        AlertDialog.Builder alertDialogue=new AlertDialog.Builder(Cart.this);

        alertDialogue.setTitle("One more step!");

        alertDialogue.setMessage("Enter your address :");




        final EditText edtAddress=new EditText(Cart.this);

        LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(

                LinearLayout.LayoutParams.MATCH_PARENT,

                LinearLayout.LayoutParams.MATCH_PARENT

        );



        edtAddress.setLayoutParams(lp);

        alertDialogue.setView(edtAddress);  //Add edit text to alert dialog

        alertDialogue.setIcon(R.drawable.ic_shopping_cart_black_24dp);



        alertDialogue.setPositiveButton("YES", new DialogInterface.OnClickListener() {

            @Override

            public void onClick(DialogInterface dialog, int which) {


                //Create new request


                Request request=new Request(


                        Common.currentUser.getPhone(),

                        Common.currentUser.getName(),

                        txtTotalPrice.getText().toString(),

                        edtAddress.getText().toString(),

                        cart


                );



偶然的你
浏览 39回答 1
1回答

慕妹3146593

这有点难以理解,但看起来这会给您带来错误,因为您的cleanCart方法有一个Order order需要根据数据库类传入的参数。但是,当您调用该方法时,调用该方法时不带任何参数。因为您根本没有Order在cleanCart方法中使用对象,所以可以从方法中删除参数,如下所示:数据库类:public void cleanCart() { // remove parameter    SQLiteDatabase db = getReadableDatabase();    String query = String.format("DELETE FROM OrderDetail");    db.execSQL(query);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java