Good first I have this class User
package com.example.leaftime.rocketdefender;
/** * Created by Leaftime on 04/11/2017. */
public class User {
private Integer id;
private String name;
private Integer score;
public User(Integer id, String name, Integer score)
{
this.id = id;
this.name = name;
this.score = score;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getScore() {
return score;
}
public void setScore(Integer score) {
this.score = score;
}
}
that simply takes care of the gets and sets of the id, name and score in a database sqlite that come integrated in android Studio and my error is the following
package com.example.leaftime.rocketdefender;
import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView;
import com.example.leaftime.rocketdefender.utils.utility;
import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List;
public class HighscoreListActivity extends AppCompatActivity {
ListView highLIST;
ArrayList<String> listInfo;
ArrayList<User> listUsers;
ConectionSQLiteHelper conn;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_highscore_list);
conn = new ConectionSQLiteHelper(getApplicationContext(), "bd users", null, 1);
highLIST = (ListView) findViewById(R.id.highscoreList);
getListPersons();
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, listInfo);
highLIST.setAdapter(adapter);
}
private void getListPersons()
{
SQLiteDatabase db = conn.getReadableDatabase();
User user = null;
listUsers = new ArrayList<User>();
//select * from users
Cursor cursor = db.rawQuery("SELECT * FROM " + utility.TABLE_USER, null);
while(cursor.moveToNext())
{
user = new User();
user.setId(cursor.getInt(0));
user.setName(cursor.getString(1));
user.setScore(cursor.getInt(2));
listUsers.add(user);
}
obtainList();
}
private void obtainList()
{
listInfo = new ArrayList<String>();
for (int i = 0; i < listUsers.size(); i++)
{
listInfo.add(listUsers.get(i).getId() + " - " + listUsers.get(i).getName());
}
}
}
in this part I declare a user coming from User () is null User user = null;
and to create an instance in a listview I have this
while(cursor.moveToNext())
{
user = new User();
user.setId(cursor.getInt(0));
user.setName(cursor.getString(1));
user.setScore(cursor.getInt(2));
listUsers.add(user);
}
what it does is create each of the items in list view but when calling it in user = new User () it asks me to pass some parameters, specifically tell me User () in User can not be applied to: parameters arguments; Can someone give me a clue how to solve this problem?