문제

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());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top