简体   繁体   中英

How can I write the ArrayList count to LogCat?

In testing a query that returns N records, I want to log the count of records returned, but this attempt to do so:

Button fetchVendorsByCoBtn = (Button) findViewById(R.id.fetchVendorsByCoBtn);
fetchVendorsByCoBtn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        SQLiteHandlerVendors sqliteHandler = new SQLiteHandlerVendors(MainActivity.this, null, null, 1);
        ArrayList<Vendor> vens = sqliteHandler.findVendorsByCompanyName("[blank]");
        Log.i("Number of blankety-blank Vendors found", ((String) vens.size()));
    }
});

...fails with, " error: incompatible types: int cannot be converted to String "

...as does this:

Log.i("Number of matching Vendors found", ((String) vens.size()));

It would seem an int val would automatically get converted to String, and if not, at least a cast would work; but neither do.

How can I legally log this value?

Try

String.valueOf( vens.size());

or

Integer.toString( vens.size());

You can't assign an int to String.

Alternative minimalistic way:

vens.size() + ""

so your log would look like this:

Log.i("Number of matching Vendors found", vens.size()+"");

have you tried toString()

vens.size().toString()

Alternatively try doing this:

String.format("%d",vens.size());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM