Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在代码中找不到错误_Java_Android_Android Sqlite - Fatal编程技术网

Java 在代码中找不到错误

Java 在代码中找不到错误,java,android,android-sqlite,Java,Android,Android Sqlite,大家好,我有一个小问题,我更改了sql数据库代码和我的活动代码。。。现在,当我尝试启动活动时,应用程序崩溃(1)。我也给你sql数据库代码(2)。以及logcat(3)中的文本 (1): package com.peky.smartornot; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widg

大家好,我有一个小问题,我更改了sql数据库代码和我的活动代码。。。现在,当我尝试启动活动时,应用程序崩溃(1)。我也给你sql数据库代码(2)。以及logcat(3)中的文本

(1):

package com.peky.smartornot;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.Toast;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class POV1 extends Activity {
    Sql ulaz = new Sql(this);
    TextView joke4text;
    TextView joke3text;
    TextView joke2text;
    TextView joke1text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pov1);
        sve();
    }

    public void sve() {
        // TODO Auto-generated method stub
        ulaz.open();
        int joker1 = ulaz.procitaj(), joker2 = ulaz.procitaj2(), joker3 = ulaz
                .procitaj3(), joker4 = ulaz.procitaj4();
        ulaz.close();
        TabHost joker = (TabHost) findViewById(R.id.tabhost);
        joker.setup();
        TabSpec izgled = joker.newTabSpec("tag1");
        izgled.setContent(R.id.tab1);
        izgled.setIndicator("Joker 1");
        joker.addTab(izgled);
        izgled = joker.newTabSpec("tag2");
        izgled.setContent(R.id.tab2);
        izgled.setIndicator("Joker 2");
        joker.addTab(izgled);
        izgled = joker.newTabSpec("tag3");
        izgled.setContent(R.id.tab3);
        izgled.setIndicator("Joker 3");
        joker.addTab(izgled);
        izgled = joker.newTabSpec("tag4");
        izgled.setContent(R.id.tab4);
        izgled.setIndicator("Joker 4");
        joker.addTab(izgled);
        joke1text = (TextView) findViewById(R.id.joker1text);
        joke1text.setText("You have " + joker1 + " jokers !");
        joke2text = (TextView) findViewById(R.id.joker2text);
        joke2text.setText("You have " + joker2 + " jokers !");
        joke3text = (TextView) findViewById(R.id.joker3text);
        joke3text.setText("You have " + joker3 + " jokers !");
        joke4text = (TextView) findViewById(R.id.joker4text);
        joke4text.setText("You have " + joker4 + " jokers !");
    }

    public void joker1(View view) {
        Button netocan = (Button) findViewById(R.id.button5);
        Button netocan2 = (Button) findViewById(R.id.button4);
        Button netocan3 = (Button) findViewById(R.id.button2);
        ulaz.open();
        int joker1=ulaz.procitaj(),joker2,joker3,joker4;
        ulaz.close();
        if (joker1 != 0) {
            if(netocan.getVisibility()==View.VISIBLE){
                netocan.setVisibility(View.INVISIBLE);
                ulaz.open();
                joker1=joker1-1;
                joker2=ulaz.procitaj2();
                joker3=ulaz.procitaj3();
                joker4=ulaz.procitaj4();
                ulaz.spremijoker(joker1, joker2, joker3, joker4);
                ulaz.close();
                joke1text = (TextView) findViewById(R.id.joker1text);
                joke1text.setText("You have " + joker1 + " jokers !");
            }else if(netocan2.getVisibility()==View.VISIBLE){
                netocan2.setVisibility(View.INVISIBLE);
                ulaz.open();
                joker1=joker1-1;
                joker2=ulaz.procitaj2();
                joker3=ulaz.procitaj3();
                joker4=ulaz.procitaj4();
                ulaz.spremijoker(joker1, joker2, joker3, joker4);
                ulaz.close();
                joke1text = (TextView) findViewById(R.id.joker1text);
                joke1text.setText("You have " + joker1 + " jokers !");
            }else if(netocan3.getVisibility()==View.VISIBLE){
                netocan3.setVisibility(View.INVISIBLE);
                ulaz.open();
                joker1=joker1-1;
                joker2=ulaz.procitaj2();
                joker3=ulaz.procitaj3();
                joker4=ulaz.procitaj4();
                ulaz.spremijoker(joker1, joker2, joker3, joker4);
                ulaz.close();
                joke1text = (TextView) findViewById(R.id.joker1text);
                joke1text.setText("You have " + joker1 + " jokers !");
            }else{
                Toast imasodgovor=Toast.makeText(getApplicationContext(), "You can not use more JOKERS1 on this question !", Toast.LENGTH_SHORT);
                imasodgovor.show();
            }

        }else{
            Toast nemasjokera=Toast.makeText(getApplicationContext(), "You dont have enought JOKERS1 !", Toast.LENGTH_SHORT);
            nemasjokera.show();
        }

    }

    public void joker4(View view) {
        ulaz.open();
        int joker1,joker2,joker3,joker4=ulaz.procitaj4();
        ulaz.close();
        Button netocan = (Button) findViewById(R.id.button5);
        Button netocan2 = (Button) findViewById(R.id.button4);
        Button netocan3 = (Button) findViewById(R.id.button2);
        if (joker4 != 0) {
            if(netocan.getVisibility()==View.VISIBLE || netocan2.getVisibility()==View.VISIBLE || netocan3.getVisibility()==View.VISIBLE){
            netocan.setVisibility(View.INVISIBLE);
            netocan2.setVisibility(View.INVISIBLE);
            netocan3.setVisibility(View.INVISIBLE);
            ulaz.open();
            joker1=ulaz.procitaj();
            joker2=ulaz.procitaj2();
            joker3=ulaz.procitaj3();
            joker4=joker4 - 1;;
            ulaz.spremijoker(joker1, joker2, joker3, joker4);
            ulaz.close();
            joke4text = (TextView) findViewById(R.id.joker4text);
            joke4text.setText("You have " + joker4 + " jokers !");}else{
                Toast imasodgovor=Toast.makeText(getApplicationContext(), "You can not use more JOKERS4 on this question !", Toast.LENGTH_SHORT);
                imasodgovor.show();
            }
        } else {
            Toast jokertext = Toast.makeText(getApplicationContext(),
                    "Not enought JOKERS4", Toast.LENGTH_SHORT);
            jokertext.show();

        }
    }

    public void joker2(View view){

    }
    public void tocan(View view){
    }
    public void netocanodgovor(View view) {
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.pov1, menu);
        return false;
    }

}
package com.peky.smartornot;

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

public class Sql {
    public static final String KEY_ROWID = "_id";
    public static final String KEY_JOKER1 = "joker";
    public static final String KEY_JOKER2 = "joker2";
    public static final String KEY_JOKER3 = "joker3";
    public static final String KEY_JOKER4 = "joker4";

    private static final String DATABASE_NAME = "SQL";
    private static final String DATABASE_TABLE = "peoples_table";
    private static final int DATABASE_VERSION = 1;

    private DbHelper ourHelper;
    private final Context ourContext;
    private SQLiteDatabase ourDatabase;

    private static class DbHelper extends SQLiteOpenHelper {

        public DbHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            // TODO Auto-generated constructor stub
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub
            db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID
                    + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_JOKER1
                    + " INTEGER, " + KEY_JOKER2 + " INTEGER, " + KEY_JOKER3
                    + " INTEGER, " + KEY_JOKER4 + " INTEGER);");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
            db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
            onCreate(db);
        }

    }

    public Sql(Context c) {
        ourContext = c;
    }

    public Sql open() {
        ourHelper = new DbHelper(ourContext);
        ourDatabase = ourHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        ourHelper.close();
    }

    public long spremijoker(int joker1, int joker2, int joker3, int joker4) {
        // TODO Auto-generated method stub
        ContentValues cv = new ContentValues();

        cv.put(KEY_JOKER1, joker1);

        cv.put(KEY_JOKER2, joker2);

        cv.put(KEY_JOKER3, joker3);

        cv.put(KEY_JOKER4, joker4);

        return ourDatabase.insert(DATABASE_TABLE, null, cv);

    }

    public int procitaj() {
        // TODO Auto-generated method stub
        String[] columns = new String[] { KEY_ROWID, KEY_JOKER1 };
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                null, null);
        int citac = 0;
        int iJokerammount = c.getColumnIndex(KEY_JOKER1);
        c.moveToLast();
        citac = c.getInt(iJokerammount);

        return citac;

    }

    public int procitaj2() {
        // TODO Auto-generated method stub
        // TODO Auto-generated method stub
        String[] columns = new String[] { KEY_ROWID, KEY_JOKER2 };
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                null, null);
        int citac = 0;
        int iJoker2 = c.getColumnIndex(KEY_JOKER2);
        c.moveToLast();
        citac = c.getInt(iJoker2);

        return citac;

    }

    public int procitaj3() {
        // TODO Auto-generated method stub
        // TODO Auto-generated method stub
        String[] columns = new String[] { KEY_ROWID, KEY_JOKER3 };
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                null, null);
        int citac = 0;
        int iJoker3 = c.getColumnIndex(KEY_JOKER3);
        c.moveToLast();
        citac = c.getInt(iJoker3);

        return citac;

    }

    public int procitaj4() {
        // TODO Auto-generated method stub
        // TODO Auto-generated method stub
        String[] columns = new String[] { KEY_ROWID, KEY_JOKER4 };
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                null, null);
        int citac = 0;
        int iJoker4 = c.getColumnIndex(KEY_JOKER4);
        c.moveToLast();
        citac = c.getInt(iJoker4);

        return citac;

    }

}
c.moveToLast;
(2):

package com.peky.smartornot;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.Toast;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class POV1 extends Activity {
    Sql ulaz = new Sql(this);
    TextView joke4text;
    TextView joke3text;
    TextView joke2text;
    TextView joke1text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pov1);
        sve();
    }

    public void sve() {
        // TODO Auto-generated method stub
        ulaz.open();
        int joker1 = ulaz.procitaj(), joker2 = ulaz.procitaj2(), joker3 = ulaz
                .procitaj3(), joker4 = ulaz.procitaj4();
        ulaz.close();
        TabHost joker = (TabHost) findViewById(R.id.tabhost);
        joker.setup();
        TabSpec izgled = joker.newTabSpec("tag1");
        izgled.setContent(R.id.tab1);
        izgled.setIndicator("Joker 1");
        joker.addTab(izgled);
        izgled = joker.newTabSpec("tag2");
        izgled.setContent(R.id.tab2);
        izgled.setIndicator("Joker 2");
        joker.addTab(izgled);
        izgled = joker.newTabSpec("tag3");
        izgled.setContent(R.id.tab3);
        izgled.setIndicator("Joker 3");
        joker.addTab(izgled);
        izgled = joker.newTabSpec("tag4");
        izgled.setContent(R.id.tab4);
        izgled.setIndicator("Joker 4");
        joker.addTab(izgled);
        joke1text = (TextView) findViewById(R.id.joker1text);
        joke1text.setText("You have " + joker1 + " jokers !");
        joke2text = (TextView) findViewById(R.id.joker2text);
        joke2text.setText("You have " + joker2 + " jokers !");
        joke3text = (TextView) findViewById(R.id.joker3text);
        joke3text.setText("You have " + joker3 + " jokers !");
        joke4text = (TextView) findViewById(R.id.joker4text);
        joke4text.setText("You have " + joker4 + " jokers !");
    }

    public void joker1(View view) {
        Button netocan = (Button) findViewById(R.id.button5);
        Button netocan2 = (Button) findViewById(R.id.button4);
        Button netocan3 = (Button) findViewById(R.id.button2);
        ulaz.open();
        int joker1=ulaz.procitaj(),joker2,joker3,joker4;
        ulaz.close();
        if (joker1 != 0) {
            if(netocan.getVisibility()==View.VISIBLE){
                netocan.setVisibility(View.INVISIBLE);
                ulaz.open();
                joker1=joker1-1;
                joker2=ulaz.procitaj2();
                joker3=ulaz.procitaj3();
                joker4=ulaz.procitaj4();
                ulaz.spremijoker(joker1, joker2, joker3, joker4);
                ulaz.close();
                joke1text = (TextView) findViewById(R.id.joker1text);
                joke1text.setText("You have " + joker1 + " jokers !");
            }else if(netocan2.getVisibility()==View.VISIBLE){
                netocan2.setVisibility(View.INVISIBLE);
                ulaz.open();
                joker1=joker1-1;
                joker2=ulaz.procitaj2();
                joker3=ulaz.procitaj3();
                joker4=ulaz.procitaj4();
                ulaz.spremijoker(joker1, joker2, joker3, joker4);
                ulaz.close();
                joke1text = (TextView) findViewById(R.id.joker1text);
                joke1text.setText("You have " + joker1 + " jokers !");
            }else if(netocan3.getVisibility()==View.VISIBLE){
                netocan3.setVisibility(View.INVISIBLE);
                ulaz.open();
                joker1=joker1-1;
                joker2=ulaz.procitaj2();
                joker3=ulaz.procitaj3();
                joker4=ulaz.procitaj4();
                ulaz.spremijoker(joker1, joker2, joker3, joker4);
                ulaz.close();
                joke1text = (TextView) findViewById(R.id.joker1text);
                joke1text.setText("You have " + joker1 + " jokers !");
            }else{
                Toast imasodgovor=Toast.makeText(getApplicationContext(), "You can not use more JOKERS1 on this question !", Toast.LENGTH_SHORT);
                imasodgovor.show();
            }

        }else{
            Toast nemasjokera=Toast.makeText(getApplicationContext(), "You dont have enought JOKERS1 !", Toast.LENGTH_SHORT);
            nemasjokera.show();
        }

    }

    public void joker4(View view) {
        ulaz.open();
        int joker1,joker2,joker3,joker4=ulaz.procitaj4();
        ulaz.close();
        Button netocan = (Button) findViewById(R.id.button5);
        Button netocan2 = (Button) findViewById(R.id.button4);
        Button netocan3 = (Button) findViewById(R.id.button2);
        if (joker4 != 0) {
            if(netocan.getVisibility()==View.VISIBLE || netocan2.getVisibility()==View.VISIBLE || netocan3.getVisibility()==View.VISIBLE){
            netocan.setVisibility(View.INVISIBLE);
            netocan2.setVisibility(View.INVISIBLE);
            netocan3.setVisibility(View.INVISIBLE);
            ulaz.open();
            joker1=ulaz.procitaj();
            joker2=ulaz.procitaj2();
            joker3=ulaz.procitaj3();
            joker4=joker4 - 1;;
            ulaz.spremijoker(joker1, joker2, joker3, joker4);
            ulaz.close();
            joke4text = (TextView) findViewById(R.id.joker4text);
            joke4text.setText("You have " + joker4 + " jokers !");}else{
                Toast imasodgovor=Toast.makeText(getApplicationContext(), "You can not use more JOKERS4 on this question !", Toast.LENGTH_SHORT);
                imasodgovor.show();
            }
        } else {
            Toast jokertext = Toast.makeText(getApplicationContext(),
                    "Not enought JOKERS4", Toast.LENGTH_SHORT);
            jokertext.show();

        }
    }

    public void joker2(View view){

    }
    public void tocan(View view){
    }
    public void netocanodgovor(View view) {
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.pov1, menu);
        return false;
    }

}
package com.peky.smartornot;

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

public class Sql {
    public static final String KEY_ROWID = "_id";
    public static final String KEY_JOKER1 = "joker";
    public static final String KEY_JOKER2 = "joker2";
    public static final String KEY_JOKER3 = "joker3";
    public static final String KEY_JOKER4 = "joker4";

    private static final String DATABASE_NAME = "SQL";
    private static final String DATABASE_TABLE = "peoples_table";
    private static final int DATABASE_VERSION = 1;

    private DbHelper ourHelper;
    private final Context ourContext;
    private SQLiteDatabase ourDatabase;

    private static class DbHelper extends SQLiteOpenHelper {

        public DbHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            // TODO Auto-generated constructor stub
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub
            db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID
                    + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_JOKER1
                    + " INTEGER, " + KEY_JOKER2 + " INTEGER, " + KEY_JOKER3
                    + " INTEGER, " + KEY_JOKER4 + " INTEGER);");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
            db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
            onCreate(db);
        }

    }

    public Sql(Context c) {
        ourContext = c;
    }

    public Sql open() {
        ourHelper = new DbHelper(ourContext);
        ourDatabase = ourHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        ourHelper.close();
    }

    public long spremijoker(int joker1, int joker2, int joker3, int joker4) {
        // TODO Auto-generated method stub
        ContentValues cv = new ContentValues();

        cv.put(KEY_JOKER1, joker1);

        cv.put(KEY_JOKER2, joker2);

        cv.put(KEY_JOKER3, joker3);

        cv.put(KEY_JOKER4, joker4);

        return ourDatabase.insert(DATABASE_TABLE, null, cv);

    }

    public int procitaj() {
        // TODO Auto-generated method stub
        String[] columns = new String[] { KEY_ROWID, KEY_JOKER1 };
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                null, null);
        int citac = 0;
        int iJokerammount = c.getColumnIndex(KEY_JOKER1);
        c.moveToLast();
        citac = c.getInt(iJokerammount);

        return citac;

    }

    public int procitaj2() {
        // TODO Auto-generated method stub
        // TODO Auto-generated method stub
        String[] columns = new String[] { KEY_ROWID, KEY_JOKER2 };
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                null, null);
        int citac = 0;
        int iJoker2 = c.getColumnIndex(KEY_JOKER2);
        c.moveToLast();
        citac = c.getInt(iJoker2);

        return citac;

    }

    public int procitaj3() {
        // TODO Auto-generated method stub
        // TODO Auto-generated method stub
        String[] columns = new String[] { KEY_ROWID, KEY_JOKER3 };
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                null, null);
        int citac = 0;
        int iJoker3 = c.getColumnIndex(KEY_JOKER3);
        c.moveToLast();
        citac = c.getInt(iJoker3);

        return citac;

    }

    public int procitaj4() {
        // TODO Auto-generated method stub
        // TODO Auto-generated method stub
        String[] columns = new String[] { KEY_ROWID, KEY_JOKER4 };
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                null, null);
        int citac = 0;
        int iJoker4 = c.getColumnIndex(KEY_JOKER4);
        c.moveToLast();
        citac = c.getInt(iJoker4);

        return citac;

    }

}
c.moveToLast;
(3) :


你的错误说明了一切:

CursorIndexOutOfBoundsException:请求索引-1,大小为0

您正试图访问元素索引为
-1
的内容的空列表<代码>-1在Java中从来都不是有效的数组索引,因此存在两个问题:

  • 如果确实不需要,为什么列表是空的
  • 是什么导致
    -1
    的索引值不正确

  • 因为
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
    是问题产生的地方,这就是你需要寻找的地方。您的代码中有什么东西在调用它?由于
    performLaunchActivity
    不在您发布的代码中(您的
    main
    函数也不在其中),而且您的堆栈跟踪也不太彻底,我们需要更多信息才能进一步帮助您。

    我找到了一个解决我在procitaj方法中设置的问题的方法:

    for(c.moveToFirst;!c.isAfterLast;c.moveToNext){
     citac = c.getInt(iJoker4);
    }
    
    而不是:

    package com.peky.smartornot;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TabHost;
    import android.widget.Toast;
    import android.widget.TabHost.TabSpec;
    import android.widget.TextView;
    
    public class POV1 extends Activity {
        Sql ulaz = new Sql(this);
        TextView joke4text;
        TextView joke3text;
        TextView joke2text;
        TextView joke1text;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_pov1);
            sve();
        }
    
        public void sve() {
            // TODO Auto-generated method stub
            ulaz.open();
            int joker1 = ulaz.procitaj(), joker2 = ulaz.procitaj2(), joker3 = ulaz
                    .procitaj3(), joker4 = ulaz.procitaj4();
            ulaz.close();
            TabHost joker = (TabHost) findViewById(R.id.tabhost);
            joker.setup();
            TabSpec izgled = joker.newTabSpec("tag1");
            izgled.setContent(R.id.tab1);
            izgled.setIndicator("Joker 1");
            joker.addTab(izgled);
            izgled = joker.newTabSpec("tag2");
            izgled.setContent(R.id.tab2);
            izgled.setIndicator("Joker 2");
            joker.addTab(izgled);
            izgled = joker.newTabSpec("tag3");
            izgled.setContent(R.id.tab3);
            izgled.setIndicator("Joker 3");
            joker.addTab(izgled);
            izgled = joker.newTabSpec("tag4");
            izgled.setContent(R.id.tab4);
            izgled.setIndicator("Joker 4");
            joker.addTab(izgled);
            joke1text = (TextView) findViewById(R.id.joker1text);
            joke1text.setText("You have " + joker1 + " jokers !");
            joke2text = (TextView) findViewById(R.id.joker2text);
            joke2text.setText("You have " + joker2 + " jokers !");
            joke3text = (TextView) findViewById(R.id.joker3text);
            joke3text.setText("You have " + joker3 + " jokers !");
            joke4text = (TextView) findViewById(R.id.joker4text);
            joke4text.setText("You have " + joker4 + " jokers !");
        }
    
        public void joker1(View view) {
            Button netocan = (Button) findViewById(R.id.button5);
            Button netocan2 = (Button) findViewById(R.id.button4);
            Button netocan3 = (Button) findViewById(R.id.button2);
            ulaz.open();
            int joker1=ulaz.procitaj(),joker2,joker3,joker4;
            ulaz.close();
            if (joker1 != 0) {
                if(netocan.getVisibility()==View.VISIBLE){
                    netocan.setVisibility(View.INVISIBLE);
                    ulaz.open();
                    joker1=joker1-1;
                    joker2=ulaz.procitaj2();
                    joker3=ulaz.procitaj3();
                    joker4=ulaz.procitaj4();
                    ulaz.spremijoker(joker1, joker2, joker3, joker4);
                    ulaz.close();
                    joke1text = (TextView) findViewById(R.id.joker1text);
                    joke1text.setText("You have " + joker1 + " jokers !");
                }else if(netocan2.getVisibility()==View.VISIBLE){
                    netocan2.setVisibility(View.INVISIBLE);
                    ulaz.open();
                    joker1=joker1-1;
                    joker2=ulaz.procitaj2();
                    joker3=ulaz.procitaj3();
                    joker4=ulaz.procitaj4();
                    ulaz.spremijoker(joker1, joker2, joker3, joker4);
                    ulaz.close();
                    joke1text = (TextView) findViewById(R.id.joker1text);
                    joke1text.setText("You have " + joker1 + " jokers !");
                }else if(netocan3.getVisibility()==View.VISIBLE){
                    netocan3.setVisibility(View.INVISIBLE);
                    ulaz.open();
                    joker1=joker1-1;
                    joker2=ulaz.procitaj2();
                    joker3=ulaz.procitaj3();
                    joker4=ulaz.procitaj4();
                    ulaz.spremijoker(joker1, joker2, joker3, joker4);
                    ulaz.close();
                    joke1text = (TextView) findViewById(R.id.joker1text);
                    joke1text.setText("You have " + joker1 + " jokers !");
                }else{
                    Toast imasodgovor=Toast.makeText(getApplicationContext(), "You can not use more JOKERS1 on this question !", Toast.LENGTH_SHORT);
                    imasodgovor.show();
                }
    
            }else{
                Toast nemasjokera=Toast.makeText(getApplicationContext(), "You dont have enought JOKERS1 !", Toast.LENGTH_SHORT);
                nemasjokera.show();
            }
    
        }
    
        public void joker4(View view) {
            ulaz.open();
            int joker1,joker2,joker3,joker4=ulaz.procitaj4();
            ulaz.close();
            Button netocan = (Button) findViewById(R.id.button5);
            Button netocan2 = (Button) findViewById(R.id.button4);
            Button netocan3 = (Button) findViewById(R.id.button2);
            if (joker4 != 0) {
                if(netocan.getVisibility()==View.VISIBLE || netocan2.getVisibility()==View.VISIBLE || netocan3.getVisibility()==View.VISIBLE){
                netocan.setVisibility(View.INVISIBLE);
                netocan2.setVisibility(View.INVISIBLE);
                netocan3.setVisibility(View.INVISIBLE);
                ulaz.open();
                joker1=ulaz.procitaj();
                joker2=ulaz.procitaj2();
                joker3=ulaz.procitaj3();
                joker4=joker4 - 1;;
                ulaz.spremijoker(joker1, joker2, joker3, joker4);
                ulaz.close();
                joke4text = (TextView) findViewById(R.id.joker4text);
                joke4text.setText("You have " + joker4 + " jokers !");}else{
                    Toast imasodgovor=Toast.makeText(getApplicationContext(), "You can not use more JOKERS4 on this question !", Toast.LENGTH_SHORT);
                    imasodgovor.show();
                }
            } else {
                Toast jokertext = Toast.makeText(getApplicationContext(),
                        "Not enought JOKERS4", Toast.LENGTH_SHORT);
                jokertext.show();
    
            }
        }
    
        public void joker2(View view){
    
        }
        public void tocan(View view){
        }
        public void netocanodgovor(View view) {
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.pov1, menu);
            return false;
        }
    
    }
    
    package com.peky.smartornot;
    
    import android.content.ContentValues;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    
    public class Sql {
        public static final String KEY_ROWID = "_id";
        public static final String KEY_JOKER1 = "joker";
        public static final String KEY_JOKER2 = "joker2";
        public static final String KEY_JOKER3 = "joker3";
        public static final String KEY_JOKER4 = "joker4";
    
        private static final String DATABASE_NAME = "SQL";
        private static final String DATABASE_TABLE = "peoples_table";
        private static final int DATABASE_VERSION = 1;
    
        private DbHelper ourHelper;
        private final Context ourContext;
        private SQLiteDatabase ourDatabase;
    
        private static class DbHelper extends SQLiteOpenHelper {
    
            public DbHelper(Context context) {
                super(context, DATABASE_NAME, null, DATABASE_VERSION);
                // TODO Auto-generated constructor stub
            }
    
            @Override
            public void onCreate(SQLiteDatabase db) {
                // TODO Auto-generated method stub
                db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID
                        + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_JOKER1
                        + " INTEGER, " + KEY_JOKER2 + " INTEGER, " + KEY_JOKER3
                        + " INTEGER, " + KEY_JOKER4 + " INTEGER);");
            }
    
            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                // TODO Auto-generated method stub
                db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
                onCreate(db);
            }
    
        }
    
        public Sql(Context c) {
            ourContext = c;
        }
    
        public Sql open() {
            ourHelper = new DbHelper(ourContext);
            ourDatabase = ourHelper.getWritableDatabase();
            return this;
        }
    
        public void close() {
            ourHelper.close();
        }
    
        public long spremijoker(int joker1, int joker2, int joker3, int joker4) {
            // TODO Auto-generated method stub
            ContentValues cv = new ContentValues();
    
            cv.put(KEY_JOKER1, joker1);
    
            cv.put(KEY_JOKER2, joker2);
    
            cv.put(KEY_JOKER3, joker3);
    
            cv.put(KEY_JOKER4, joker4);
    
            return ourDatabase.insert(DATABASE_TABLE, null, cv);
    
        }
    
        public int procitaj() {
            // TODO Auto-generated method stub
            String[] columns = new String[] { KEY_ROWID, KEY_JOKER1 };
            Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                    null, null);
            int citac = 0;
            int iJokerammount = c.getColumnIndex(KEY_JOKER1);
            c.moveToLast();
            citac = c.getInt(iJokerammount);
    
            return citac;
    
        }
    
        public int procitaj2() {
            // TODO Auto-generated method stub
            // TODO Auto-generated method stub
            String[] columns = new String[] { KEY_ROWID, KEY_JOKER2 };
            Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                    null, null);
            int citac = 0;
            int iJoker2 = c.getColumnIndex(KEY_JOKER2);
            c.moveToLast();
            citac = c.getInt(iJoker2);
    
            return citac;
    
        }
    
        public int procitaj3() {
            // TODO Auto-generated method stub
            // TODO Auto-generated method stub
            String[] columns = new String[] { KEY_ROWID, KEY_JOKER3 };
            Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                    null, null);
            int citac = 0;
            int iJoker3 = c.getColumnIndex(KEY_JOKER3);
            c.moveToLast();
            citac = c.getInt(iJoker3);
    
            return citac;
    
        }
    
        public int procitaj4() {
            // TODO Auto-generated method stub
            // TODO Auto-generated method stub
            String[] columns = new String[] { KEY_ROWID, KEY_JOKER4 };
            Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                    null, null);
            int citac = 0;
            int iJoker4 = c.getColumnIndex(KEY_JOKER4);
            c.moveToLast();
            citac = c.getInt(iJoker4);
    
            return citac;
    
        }
    
    }
    
    c.moveToLast;
    

    无论如何谢谢你

    你确定这是完整的日志吗?另外,到目前为止,您在追踪问题方面做了哪些尝试?还要检查一下我还没有看过你的代码,但是如果你从-1是有效索引的其他语言迁移,你必须将它更改为
    List.getLength()-1
    或类似的语言。在Java中将“从不”更改为“从不”。因此,如果我在创建代码时添加一个内容值以将0放入其中,它可以解决我的问题吗?不,最小值应该是0,我猜列表是空的。我会尝试一下。如果没有看到更多相关的代码,我不能肯定,但肯定值得一试。