API から取得したデータを表示しようとしています。データをテキストビューおよびログとして表示できますが、リストとして表示することはできません。
エラー " Cannot resolve constructor
"が表示されます
Error:(72, 68) error: no suitable constructor found for ArrayAdapter(<anonymous FutureCallback<JsonArray>>,int,ArrayList<String>)
constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable
ここに完全なエラーコードがあります
Error:(72, 68) error: no suitable constructor found for ArrayAdapter(<anonymous FutureCallback<JsonArray>>,int,ArrayList<String>)
constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable
(argument mismatch; <anonymous FutureCallback<JsonArray>> cannot be converted to Context)
constructor ArrayAdapter.ArrayAdapter(Context,int,String[]) is not applicable
(argument mismatch; <anonymous FutureCallback<JsonArray>> cannot be converted to Context)
constructor ArrayAdapter.ArrayAdapter(Context,int,List<String>) is not applicable
(argument mismatch; <anonymous FutureCallback<JsonArray>> cannot be converted to Context)
public class MainActivity extends AppCompatActivity {
ListView lView;
TextView tView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lView = (ListView) findViewById(R.id.lv);
tView = (TextView) findViewById(R.id.textView);
Ion.with(this).
load("https://jsonplaceholder.typicode.com/users").
asJsonArray().
setCallback(
new FutureCallback<JsonArray>()
{
@Override
public void onCompleted(final Exception ex,
final JsonArray array)
{
if(ex != null)
{
Toast.makeText(MainActivity.this,
"Error: " + ex.getMessage(),
Toast.LENGTH_LONG).show();
}
else
{
ArrayList<String> list = new ArrayList<String>();
for(final JsonElement element : array)
{
final JsonObject json;
final JsonElement nameElement;
final JsonElement usernameElement;
final String name;
final String username;
json = element.getAsJsonObject();
nameElement = json.get("name");
usernameElement = json.get("username");
name = nameElement.getAsString();
username = usernameElement.getAsString();
Log.d("X",
name + " -> " + username);
list.add(name);
list.add(username);
tView.setText(name);
}
/*
for (int i = 0; i < array.size(); i++) {
list.add(array.get(i).toString());
}*/
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_1,list); //ERROR HERE
lView.setAdapter(adapter);
}
}
});
}