Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8514113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:46:21+00:00 2026-06-11T04:46:21+00:00

In my database i have the table AndroidGameMode but when i try to insert

  • 0

In my database i have the table AndroidGameMode but when i try to insert some data into the table i get this error that says that one of my columns doesn’t exist

    package com.example.jogodogalo.jogador1;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DataBaseHandler extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;

    private static final String DATABASE_NAME = "JogoDoGaloDB";

    private static final String TABLE_RESULTS = "AndroidGameMode";

    private static final String KEY_ID = "PlayerID";
    private static final String KEY_PLAYER = "PlayerName";
    private static final String KEY_WINS = "PlayerWins";
    private static final String KEY_TIES = "PlayerTies";
    private static final String KEY_LOSSES = "PlayerLosses";
    private static final String KEY_POINTS = "PlayerPoints";

    public DataBaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_RESULTS_TABLE = "CREATE TABLE " + TABLE_RESULTS +"("
                + KEY_ID + " INTEGER PRIMARY KEY,"
                + KEY_PLAYER + " TEXT,"
                + KEY_WINS + " INTEGER,"
                + KEY_TIES + " INTEGER," 
                + KEY_LOSSES + " INTEGER," 
                + KEY_POINTS + "INTEGER" + ")";
        db.execSQL(CREATE_RESULTS_TABLE);
    }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            //"Mata" a outra tabela se existir
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_RESULTS);

            //cria as tabelas de novo
            onCreate(db);
        }
        //podes ir po logcat e marcar aquele erro ? marcar erro?

        public void addResults(Results results){
            SQLiteDatabase db = this.getWritableDatabase();

            ContentValues values = new ContentValues();
            values.put(KEY_PLAYER, results.getName());
            values.put(KEY_WINS, results.getWins());
            values.put(KEY_TIES, results.getTies());
            values.put(KEY_LOSSES, results.getLosses());
            values.put(KEY_POINTS, results.getPoints());
            //Pede ajuda daquele gajo ok? Dizes que inseres mas nao aparece nada e mostras as funçoes... dizes que nao e preciso nem editar nem apagar ok
            db.insert(TABLE_RESULTS, null,values);
            db.close();
        }

        public float getSumPoints() {
            float result = 0;
            SQLiteDatabase db = this.getWritableDatabase();

            Cursor c = db.query(TABLE_RESULTS, 
              new String[] { "sum(" + KEY_POINTS + ")" },
              null, null, null, null, null);
            if (c.moveToFirst()) {
                result = c.getLong(0);
            }
            c.close();
            return result;
        }

        public Results getResults(int id){
            SQLiteDatabase db = this.getReadableDatabase();

            Cursor cursor = db.query(TABLE_RESULTS, new String[]{KEY_ID, KEY_PLAYER,
                    KEY_WINS, KEY_TIES, KEY_LOSSES, KEY_POINTS}, KEY_ID + "=?", new String[] {String.valueOf(id)}, 
                null, null, null, null);

            if (cursor != null) cursor.moveToFirst();

            Results Result = new Results(Integer.parseInt(cursor.getString(0)), 
                        cursor.getString(1), 
                        Integer.parseInt(cursor.getString(2)),
                        Integer.parseInt(cursor.getString(3)),
                        Integer.parseInt(cursor.getString(4)), 
                        Integer.parseInt(cursor.getString(5)));         

                return Result;
        }



        public ArrayList<Results> getAllResults(){
            ArrayList<Results> ResultsList = new ArrayList<Results>();

            SQLiteDatabase db = this.getWritableDatabase();

            Cursor cursor = db.query(TABLE_RESULTS, null, null, null, null, null, null); 

            if(cursor.moveToFirst()){
                do{
                    Results Result = new Results();
                    Result.setID(Integer.parseInt(cursor.getString(0)));
                    Result.setName(cursor.getString(1));
                    Result.setWins(Integer.parseInt(cursor.getString(2)));
                    Result.setTies(Integer.parseInt(cursor.getString(3)));
                    Result.setLosses(Integer.parseInt(cursor.getString(4)));
                    Result.setPoints(Integer.parseInt(cursor.getString(5)));

                    ResultsList.add(Result);
                }while(cursor.moveToNext());
            }
            return ResultsList;
        }

}

that is my databaseHandler class

and this one is my ResultsClass

package com.example.jogodogalo.jogador1;

public class Results {

    int _id;
    String _name;
    int _wins;
    int _ties;
    int _losses;
    int _points;

    public Results(){

    }

    public Results (int id, String name, int wins, int ties, int losses, int points){
        this._id = id;
        this._name = name;
        this._wins = wins;
        this._losses = losses;
        this._ties = ties;
        this._points=points;
    }

    public Results (String name, int wins, int ties, int losses, int points){
        this._name = name;
        this._wins = wins;
        this._ties = ties;
        this._losses = losses;
        this._points = points;
    }

    public Results(int points){
        this._points = points;
    }

    public int getID(){
        return this._id;
    }

    public void setID(int id){
        this._id = id;
    }

    public String getName(){
        return this._name;
    }

    public void setName(String name){
        this._name = name;
    }

    public int getWins(){
        return this._wins;
    }

    public void setWins(int wins){
        this._wins = wins;
    }

    public int getTies(){
        return this._ties;
    }

    public void setTies(int ties){
        this._ties = ties;
    }

    public int getLosses(){
        return this._losses;
    }

    public void setLosses(int losses){
        this._losses = losses;
    }

    public int getPoints(){
        return this._points;
    }
    //ta mal, quando se faz um set tu nao retornas nada
    public void setPoints(int points){
        this._points = points;
    }

    @Override
    public String toString() {
        return this.getName();
    }

}

My insert code

 public void onClick(DialogInterface dialog, int whichButton) {             

                    String name = mPlayerName.getText().toString();

                    String win = mPlayerCount.getText().toString();
                    int wins_jogador1 = Integer.parseInt(win);

                    String ties = mTieCount.getText().toString();
                    int ties_jogador1 = Integer.parseInt(ties);

                    String losses = mAndroidCount.getText().toString();
                    int losses_jogador1 = Integer.parseInt(losses);

                    String pontuacao = mPointsCount.getText().toString();
                    int pontuaçao_jogador1 = Integer.parseInt(pontuacao);

                    if(pontuaçao_jogador1 == 0){
                        Toast myToast = Toast.makeText(getApplicationContext(), "Não tem qualquer pontuação. \nNão é possível guardar.",
                                Toast.LENGTH_LONG);
                    myToast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL, 0, 100);
                    myToast.setDuration(3000);
                    myToast.show();

                    }else if(pontuaçao_jogador1 != 0){

                    DataBaseHandler db  = new DataBaseHandler(getApplicationContext());
                    Results theResultados = new Results(name, wins_jogador1, ties_jogador1, losses_jogador1, pontuaçao_jogador1);

                    db.addResults(theResultados);
                    //que estranho :S ele teima com o playerPoints nao sei porque diz que a cioluna nao existe

                    Intent intent = new Intent(JogoDoGalo.this, MainMenu.class);
                    JogoDoGalo.this.startActivity(intent);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:46:22+00:00Added an answer on June 11, 2026 at 4:46 am

    There is a missing space in your onCreate code:

    + KEY_POINTS + "INTEGER" + ")";
    

    Change it to:

     + KEY_POINTS + " INTEGER" + ")"; 
    

    Update

    Also try to split your column creation command using ALTER command like this:

    @Override
     public void onCreate(SQLiteDatabase db) {
         String CREATE_RESULTS_TABLE = "CREATE TABLE " + TABLE_RESULTS+" ("
                 + KEY_ID + " INTEGER PRIMARY KEY,"
                 + KEY_PLAYER + " TEXT,"
                 + KEY_WINS + " INTEGER,"
                 + KEY_TIES + " INTEGER,"
                  + KEY_LOSSES + " INTEGER"+")";
         db.execSQL(CREATE_RESULTS_TABLE);
    
         String ALTER_RESULTS_TABLE = "ALTER TABLE " + TABLE_RESULTS
                 +" ADD "+ KEY_POINTS + " INTEGER";
         db.execSQL(ALTER_RESULTS_TABLE);
     } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

MYSQL Database: I have a table of data that I need to put into
i have table in my database that have senestive data such as password field
i have database table like this +-------+--------------+----------+ | id | ip | date |
that my problem: I have database table like that: id (AI) market_id 1 6
need help in error in database pivot. i have table tamed table_score like below:
In our database we have a table with more then 100000 entries but most
In ms-access database i have a table named tableA this table has a column
I have a sql server 2008R2 with a database that have table with thousands
My database table have a Timestamp column and i am using LINQ for insert,
i have database table with few text fields which i use to filter data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.