Try
String.valueOf( vens.size());
or
Integer.toString( vens.size());
You can't assign an int to String.
Question
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?
Solution
Try
String.valueOf( vens.size());
or
Integer.toString( vens.size());
You can't assign an int to String.
OTHER TIPS
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());