美好的一天Android Studio错误的第一个参数类型。找到'java.lang.String',必填'int'
我有搜索网站,但没有得到任何东西来帮助我解决我的问题。 我是一个android的新手,并开始了一个我无法完成的项目。使用过Android Studio 2.3 应用程序的名称“匹配追踪”
确定这里
它走的 例如我的应用程序允许您跟踪匹配“橄榄球”我现在想应用到自动点添加到领先榜如果一个球队有4次或更多的尝试,那就是我卡住的地方!
我FactDBAdaptor.class
在我RugbyActivity.class EDITED *******
package za.co.sanrl.rugbyleague.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import za.co.sanrl.rugbyleague.main.MatchEvent;
import java.util.ArrayList;
/**
* Class that allows interaction with the Facts database such as insert, delete, update.
*
* @author Morne van Rooyen
*/
public class FactsDbAdapter {
public static final String KEY_MATCHID = "match_id";
public static final String KEY_TYPE = "type";
public static final String KEY_PLAYER1 = "player1";
public static final String KEY_PLAYER2 = "player2";
public static final String KEY_TEAM = "team";
public static final String KEY_TIME = "time";
private static final String DB_TABLE = "Facts";
private SQLiteDatabase db;
private BaseHelper dbHelper;
private Context context;
public FactsDbAdapter(Context context) {
this.context = context;
}
/**
* Open database so we can write to it.
*
* @return Open DB connection
* @throws SQLException
*/
public FactsDbAdapter open() throws SQLException {
dbHelper = new BaseHelper(context);
db = dbHelper.getWritableDatabase();
return this;
}
/**
* Close database.
*/
public void close() {
dbHelper.close();
}
/**
* Add a match fact to the database.
*
* @param match_id Match ID
* @param type Goal, penalty etc.
* @param player1 First player involved in event
* @param player2 Second player involved in event
* @param team The player(s) team
* @param time The time event took place
*/
public void addMatchFact(int match_id, String type, String player1, String player2, String team, String time) {
ContentValues values = new ContentValues();
values.put(KEY_MATCHID, match_id);
values.put(KEY_TYPE, type);
values.put(KEY_PLAYER1, player1);
values.put(KEY_PLAYER2, player2);
values.put(KEY_TEAM, team);
values.put(KEY_TIME, time);
//Insert into database.
try {
db.insert(DB_TABLE, null, values);
} catch (Exception e) {
Log.e("Database error when inserting match fact", e.toString());
e.printStackTrace();
}
}
/**
* Get the column values for a specific column provided.
*
* @param column - column you want to query.
* @param duplicates - if you want duplicate results.
* @return columnlist
*/
public ArrayList<String> getColumnValues(String column, boolean duplicates) {
Cursor cursor = null;
ArrayList<String> columnList = new ArrayList<>();
//Get column values.
try {
if (duplicates) {
cursor = db.rawQuery("SELECT " + column + " FROM " + DB_TABLE, null);
} else {
cursor = db.rawQuery("SELECT DISTINCT " + column + " FROM " + DB_TABLE, null);
}
} catch (Exception e) {
Log.e("Database error selecting facts", e.toString());
e.printStackTrace();
}
//Query result is not empty.
if (cursor != null && cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndex(column);
do {
columnList.add(cursor.getString(columnIndex));
} while (cursor.moveToNext());
}
return columnList;
}
/**
* Count number of types with a given match_id.
*
* @param match_id Match ID
* @param type Event Type
* @param teamName Team Name
* @return count of types
*/
public int countTypesWithMatchID(int match_id, String type, String teamName) {
Cursor cursor = null;
ArrayList<String> columnList = new ArrayList<>();
//Get column values.
try {
cursor = db.rawQuery("SELECT " + KEY_TYPE + " FROM " + DB_TABLE +
" WHERE " + KEY_TYPE + "=? AND " + KEY_MATCHID + "=" + match_id +
" AND " + KEY_TEAM + "=?", new String[]{type, teamName});
} catch (Exception e) {
Log.e("Database error counting match events", e.toString());
e.printStackTrace();
}
//Query result is not empty.
if (cursor != null && cursor.moveToFirst()) {
int typeIndex = cursor.getColumnIndex(KEY_TYPE);
do {
columnList.add(cursor.getString(typeIndex));
} while (cursor.moveToNext());
}
return columnList.size();
}
/**Count 4 or more tries in a match begins**/
/**
* Count number of types with a given match_id.
*
* @param match_id Match ID
* @param type type is Tries
* @param teamName Team Name
* @return count of types
*/
public int countTriesWithMatchID(int match_id, String type, String teamName) {
Cursor cursor = null;
int result = 0;
//Get column values.
try {
cursor = db.rawQuery("SELECT COUNT(" + KEY_TYPE + ") FROM " + DB_TABLE +
" WHERE " + KEY_TYPE + "=Try AND " + KEY_MATCHID + "=" + match_id +
" AND " + KEY_TEAM + "=?", new String[]{type, teamName});
} catch (Exception e) {
Log.e("Database error counting match events", e.toString());
e.printStackTrace();
}
//Query result is not empty.
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getInt(0);
}
return result;
}
/**Count 4 or more tries in a match ends**/
/**
* Count the number a certain type with a certain player name comes up in db.
*
* @param type Event Type
* @param player Player involved in event
* @return count of types involving a specific player
*/
public int countTypesWithPlayer(String type, String player) {
Cursor cursor = null;
int result = 0;
//Get column values.
try {
cursor = db.rawQuery("SELECT COUNT(" + KEY_TYPE + ") FROM " + DB_TABLE +
" WHERE " + KEY_TYPE + "=? AND " + KEY_PLAYER1 + "=?", new String[]{type, player});
} catch (Exception e) {
Log.e("Db err counting type of events involving a player", e.toString());
e.printStackTrace();
}
//Query result is not empty.
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getInt(0);
}
return result;
}
/**
* Get all match facts for a given match id.
*
* @param match_id Match ID
* @return All match facts
*/
public ArrayList<MatchEvent> getAllFactsForGivenMatchID(int match_id) {
Cursor cursor = null;
ArrayList<MatchEvent> result = new ArrayList<>();
//Get column values.
try {
cursor = db.rawQuery("SELECT * FROM " + DB_TABLE + " WHERE match_id=" + match_id, null);
} catch (Exception e) {
Log.e("Db err select * events", e.toString());
e.printStackTrace();
}
//Query result is not empty.
if (cursor != null && cursor.moveToFirst()) {
int typeIndex = cursor.getColumnIndex(FactsDbAdapter.KEY_TYPE);
int player1Index = cursor.getColumnIndex(FactsDbAdapter.KEY_PLAYER1);
int player2Index = cursor.getColumnIndex(FactsDbAdapter.KEY_PLAYER2);
int teamIndex = cursor.getColumnIndex(FactsDbAdapter.KEY_TEAM);
int timeIndex = cursor.getColumnIndex(FactsDbAdapter.KEY_TIME);
do {
String type = cursor.getString(typeIndex);
String player1 = cursor.getString(player1Index);
String player2 = cursor.getString(player2Index);
String team = cursor.getString(teamIndex);
String time = cursor.getString(timeIndex);
if (player2 != null) {
MatchEvent matchEvent = new MatchEvent(time, type, player1, player2, team);
result.add(matchEvent);
} else {
MatchEvent matchEvent = new MatchEvent(time, type, player1, team);
result.add(matchEvent);
}
} while (cursor.moveToNext());
}
return result;
}
}
现在不工作的部分是本
int bpts = factsDbAdapter.countTriesWithMatchID(factsDbAdapter.KEY_MATCHID, factsDbAdapter.KEY_TYPE, factsDbAdapter.KEY_TEAM);
if (bpts<3)
任何人都可以帮助我或引导我在正确的方向请更好地描述下面的代码
switch (status) {
case WIN: {// Team won the match.
int totalWins = teamAdapter.getColumnValueForTeamInt(teamAdapter.KEY_WINS, team);
int totalPoints = teamAdapter.getColumnValueForTeamInt(teamAdapter.KEY_TOTALPOINTS, team);
int totalBonusPoints = teamAdapter.getColumnValueForTeamInt(teamAdapter.KEY_BONUSPOINTS, team);
teamAdapter.updateSingleColumn(team, teamAdapter.KEY_WINS, totalWins + 1);
int bpts = factsDbAdapter.countTriesWithMatchID(factsDbAdapter.KEY_MATCHID, factsDbAdapter.KEY_TYPE, factsDbAdapter.KEY_TEAM);
if (bpts<3) {
teamAdapter.updateSingleColumn(team, teamAdapter.KEY_BONUSPOINTS, totalBonusPoints + 1);
teamAdapter.updateSingleColumn(team, teamAdapter.KEY_TOTALPOINTS, totalPoints + 5);
}
else
{
teamAdapter.updateSingleColumn(team, teamAdapter.KEY_TOTALPOINTS, totalPoints + 4);
}
break;
}
预先感谢您
请显示'factsDbAdapter.KEY_MATCHID'的定义和值。确保它是一个'int'而不是'String'。 – john16384
@ Mark Rotteveel您好factDbAdapter.KEY_MATCHID的值应该是1到100之间的任何值,具体取决于记录的匹配数量。 – Morne
是的,但它是一个'字符串?因为预计有'int',Java不会自动转换这些类型。请显示该行代码。 – john16384