- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Android 编程方面遇到问题。我有三个类(class)。
Main2_Activity 类
public class Main2_Activity extends Activity{
ArrayList<Estekhare> estekhareHa = new ArrayList<Estekhare>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView txt_soore = (TextView) findViewById(R.id.txt_soore);
final TextView txt_aye = (TextView) findViewById(R.id.txt_aye);
final TextView txt_safhe = (TextView) findViewById(R.id.txt_safhe);
final TextView txt_koli = (TextView) findViewById(R.id.txt_koli);
final TextView txt_moamele = (TextView) findViewById(R.id.txt_moamele);
final TextView txt_ezdevaj = (TextView) findViewById(R.id.txt_ezdevaj);
final TextView txt_natije = (TextView) findViewById(R.id.txt_natije);
final TextView txt_main_aye = (TextView) findViewById(R.id.txt_main_aye);
final TextView txt_translate = (TextView) findViewById(R.id.txt_translate);
Button btnAgain=(Button) findViewById(R.id.btnAgain);
Cursor cursor = G.DB.rawQuery("SELECT * FROM Sheet1", null);
while (cursor.moveToNext()) {
Estekhare estekhare = new Estekhare();
estekhare.natije = cursor.getString(cursor.getColumnIndex("natije"));
estekhare.koli = cursor.getString(cursor.getColumnIndex("koli"));
estekhare.ezdevaj = cursor.getString(cursor.getColumnIndex("ezdevaj"));
estekhare.moamele = cursor.getString(cursor.getColumnIndex("moamele"));
estekhare.soore = cursor.getString(cursor.getColumnIndex("soore"));
estekhare.aye = cursor.getString(cursor.getColumnIndex("aye"));
estekhare.safhe = cursor.getString(cursor.getColumnIndex("safhe"));
estekhare.main_translate = cursor.getString(cursor.getColumnIndex("main_translate"));
estekhareHa.add(estekhare);
}
cursor.close();
Random rand = new Random();
int n = rand.nextInt(estekhareHa.size());
Estekhare estekhare = estekhareHa.get(n);
txt_soore.setText(estekhare.soore);
txt_aye.setText(estekhare.aye);
txt_safhe.setText(estekhare.safhe);
txt_koli.setText(estekhare.koli);
txt_moamele.setText(estekhare.moamele);
txt_ezdevaj.setText(estekhare.ezdevaj);
txt_natije.setText(estekhare.natije);
txt_main_aye.setText(estekhare.main_aye);
txt_translate.setText(estekhare.main_translate);
埃斯特卡雷级
public class Estekhare {
public String natije;
public String koli;
public String ezdevaj;
public String moamele;
public String soore;
public String aye;
public String safhe;
public String main_aye;
public String main_translate;
}
G级
public class G extends Application{
public static SQLiteDatabase DB;
public static Context context;
public static final String DIR_SDCARD=Environment.getExternalStorageDirectory().getAbsolutePath();
public static String DIR_DATABASE;
private final String dbName = "natije_estekhare.sqlite";
@Override
public void onCreate() {
super.onCreate();
context=getApplicationContext();
DIR_DATABASE= DIR_SDCARD +"/Android/data/"+ context.getPackageName()+ "/database/";
new File(DIR_DATABASE).mkdirs();
prepareDB();
}
public boolean prepareDB() {
try {
String state = Environment.getExternalStorageState();
InputStream is = G.context.getAssets().open(dbName);
if (state.equals(Environment.MEDIA_MOUNTED)) {
File DB_PATH = new File(DIR_DATABASE + "/" + dbName);
logger("SD MOUNTED");
if (DB_PATH.exists()) {
logger("DB exist");
DB = SQLiteDatabase.openOrCreateDatabase(DB_PATH, null);
return true;
}
else {
logger("DB NOT exist");
if (copy(new FileOutputStream(DB_PATH), is)) {
logger("Copy Success");
DB = SQLiteDatabase.openOrCreateDatabase(DB_PATH, null);
return true;
}
else {
logger("Copy Faild");
return false;
}
}
}
else {
logger("SD NOT MOUNTED");
DIR_DATABASE = getFilesDir().toString();
File dbFile = new File(getFilesDir().toString() + "/" + dbName);
if (dbFile.exists()) {
logger("DB exist");
DB = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
return true;
}
else {
logger("DB NOT exist");
FileOutputStream os = openFileOutput(dbName, context.MODE_PRIVATE);
if (copy(os, is)) {
logger("Copy Success");
DB = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
return true;
}
else {
logger("Copy Faild");
return false;
}
}
}
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean copy(OutputStream os, InputStream is) {
try {
int readed = 0;
byte[] buffer = new byte[8 * 1024];
while ((readed = is.read(buffer)) > 0) {
os.write(buffer, 0, readed);
}
try {
is.close();
}
catch (Exception e) {
e.printStackTrace();
}
try {
os.flush();
}
catch (Exception e) {
e.printStackTrace();
}
try {
os.close();
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
public void logger(String Message){
Log.i("LOG", Message);
}
}
当我运行这个程序时,它崩溃了。如何解决问题?
java.lang.RuntimeException: Unable to start activity ComponentInfo{amir.badiei.app.estekhareapp/amir.badiei.app.estekhareapp.Main2_Activity}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.at amir.badiei.app.estekhareapp.Main2_Activity.onCreate(Main2_Activity.java:47).
最佳答案
如果列不存在,则cursor.getColumnIndex 将返回-1。
我将开始检查以确保您的 Sheet1 表包含您尝试访问的所有列,并且它们的命名确实与您在代码中指定的方式完全相同。否则,当您尝试从光标获取 -1 列的数据时,您将收到 IllegalStateException。
关于java.lang.IllegalStateException : Couldn't read row 0, col -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39476574/
这里的 IT 网络/编程学生试图完成一项作业,但我遇到了障碍。我们的任务是读取文本文件,将单词放入 ArrayList 中,并对内容执行字符串操作。我能够将单词拉入 ArrayList、按升序对内容进
编辑:我收到以下错误代码: Error adding accessory The operation couldn’t be completed. (HMErrorDomain error 2.) 和
您好,我正在尝试测试套接字激活机制,但无法连接到服务器。 curl --unix-socket/run/gunicorn.sock本地主机 curl: (7) Couldn't connect to
所以我安装了sandbox (运行 centOS)来自 hortonworks在 virtualBox带网络配置>>> bridged network我编辑了bashrc导出http_proxy和 h
我目前正在开发一个android应用程序,提交一个post请求并处理相应的响应。 我能够将发布请求发送到相应的 URL,但是当我尝试检索响应时,我得到了一半的 HTML 内容,然后是“*无法从 STD
我在将 ServiceLoader 集成到我的 Android 应用程序以集成插件系统时遇到问题。 public class StrategieClassLoader extends URLClass
我有一个类似于以下的自定义数据类型: data Token = Number Int | Otherthings 我希望能够以一种方式使用“数字”,以另一种方式使用其他东西。所以
当我尝试从 Visual Studio Code 运行一个简单的 React Native 应用程序时,我收到以下错误消息。 Scanning folders for symlinks in C:\P
我最近从Java搬到了Kotlin。将整个项目转换为Kotlin,将pom.xml转换为build.gradle。我正在使用Kotlin,Gradle,Cucumber Sernity,Appium构
我在执行docker-compose命令时遇到Powershell中的错误: 尽管从Docker Quickstart Terminal运行相同的命令可以正常工作: 最佳答案 确保首先在Powersh
当我运行docker build时,我得到了: Sending build context to Docker daemon 10.24kB WARN[11935] Couldn't run aup
我在运行 SDL 程序时遇到此错误。它编译得很好,但是窗口打开了一小会儿然后就关闭了。 这是我的代码: //Using SDL and standard IO #include #include
我正在编写一个基于 Google map 的 Android 应用程序。应用程序本身运行良好,没有任何问题。我可以看到 map ,缩放到我的当前位置等等。根据 AndroidManifest.xml,
我在实际设备上仅在生产和开发容器上都遇到了这个错误。模拟器能够很好地获取记录。这发生在通过 XCode 运行的开发构建、TestFlight 构建和 AppStore 上的实时生产构建上。 所有设备
我正在创建一个模板化的快速排序函数,它应该允许我使用迭代器对一个定制的双向链表类进行快速排序。我遇到了错误 In file included from main.cpp:21.0: quicksort
我有一个模板类和一个具有模板返回类型的函数: template class Wrapper { public: Wrapper(const T& _data) : data(_data) {
将 Jersey 从 1.15 版升级到 1.17 版后,它开始记录以下消息: Apr 2, 2013 5:13:06 PM com.sun.jersey.server.wadl.generators
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我有一个 android 应用程序在我将设备更新到 android 4.4 (kitkat) 之前一直运行没有问题。 现在我开始收到这个错误,并且程序的某些部分在日志 cat_ 中被破坏了_ Andr
我通过 git clone 成功安装了 Directus CMS。在数据库中创建了 15 个表。在/config 文件夹中,我的 projectkey.php 文件也已创建。安装后我想使用我的凭据登录
我是一名优秀的程序员,十分优秀!