2017-03-09 78 views
-1

面对一个问题,我正在通过SQL数据库课。在模拟器上一切正常,日志显示表中有一个条目,在真实设备上 - 日志,不。设备 - 魅族M3笔记。从仿真器在模拟器上一切正常,在真正的潜水,代码不工作

package com.example.opimand.simplesqlite; 

import android.content.ContentValues; 
import android.content.Context; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 

public class MainActivity extends AppCompatActivity implements View.OnClickListener{ 

    final String LOG_TAG = "myLogs"; 

    Button btnAdd, btnRead, btnClear; 
    EditText etName, etEmail; 

    DBHelper dBhelper; 

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


     btnAdd = (Button) findViewById(R.id.btnAdd); 
     btnAdd.setOnClickListener(this); 

     btnRead = (Button) findViewById(R.id.btnRead); 
     btnRead.setOnClickListener(this); 

     btnClear = (Button) findViewById(R.id.btnClear); 
     btnClear.setOnClickListener(this); 

     etName = (EditText) findViewById(R.id.etName); 
     etEmail = (EditText) findViewById(R.id.etEmail); 

     dBhelper = new DBHelper(this); 
    } 

    @Override 
    public void onClick(View v) { 

     ContentValues cv = new ContentValues(); 

     String name = etName.getText().toString(); 
     String email = etEmail.getText().toString(); 

     SQLiteDatabase db = dBhelper.getWritableDatabase(); 


     switch (v.getId()){ 
      case R.id.btnAdd: 
      Log.d(LOG_TAG, "---Insert in my table---"); 

       cv.put("name", name); 
       cv.put("email", email); 

       long rowId = db.insert("mytable", null, cv); 
       Log.d(LOG_TAG, "raw inserted, ID "+rowId); 
       break; 

      case R.id.btnRead: 
       Log.d(LOG_TAG, "---Raws in my table ---"); 
       Cursor c = db.query("mytable",null,null,null,null,null,null); 
       if (c.moveToFirst()){ 

        int idColIndex = c.getColumnIndex("id"); 
        int nameColIndex = c.getColumnIndex("name"); 
        int emailColIndex = c.getColumnIndex("email"); 

        do { 
         Log.d(LOG_TAG, 
           "ID = "+c.getInt(idColIndex)+ 
         ", name = "+c.getString(nameColIndex)+ 
         ", email = "+c.getString(emailColIndex)); 
        } while (c.moveToNext()); 

       }else { 
        Log.d(LOG_TAG, "0 raws"); 
        c.close(); 
        break; 
       } 
      case R.id.btnClear: 
       Log.d(LOG_TAG, "---Clear my table---"); 
       int clearCount = db.delete("mytable", null, null); 
       Log.d(LOG_TAG, "deleted raws count ="+clearCount); 
       break; 
     } 
     dBhelper.close(); 
    } 

    class DBHelper extends SQLiteOpenHelper{ 

     public DBHelper(Context context) { 
      super(context, "nyDb", null, 1); 

     } 

     @Override 
     public void onCreate(SQLiteDatabase db) { 

      Log.d(LOG_TAG, "---onCreateDatabase---"); 
      db.execSQL("create table mytable (" 
      + "id integer primary key autoincrement," 
      + "name text," 
      + "email text"+");"); 
     } 

     @Override 
     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 

     } 
    } 
} 

日志 ---的onCreate数据库--- --- 中插入mytable的:--- 行插入,ID = 1

而从真实设备显示这些日志错误

03-08 12:38:56.506 5161-5161/com.example.opimand.simplesqlite E/System: stat file error, path is /data/app/com.example.opimand.simplesqlite-2/lib/arm64, exception is android.system.ErrnoException: stat failed: ENOENT (No such file or directory) 
03-08 12:38:57.448 5161-5215/com.example.opimand.simplesqlite E/GED: Failed to get GED Log Buf, err(0) 

                    [ 03-08 12:38:57.448 5161: 5215 I/   ] 
                    elapse(include ctx switch):3792 (ms), eglInitialize 
+0

您使用一些外部(第三方)的本地库? – Yazan

+0

不,我使用的所有东西都在代码中可见 – Opimand

回答

1

12月3日至8日:38:56.506 5161-5161/com.example.opimand.simplesqlite E /系统:STAT文件错误,路径是 /data/app/com.example.opimand.simplesqlite-2/lib/arm64,例外的是 android.system.ErrnoException:Stat失败:ENOENT(没有这样的文件或目录 )

我觉得你的问题的关键是在... /arm64你的应用程序,如果试图寻找一个64位的二进制文件,它可以在模拟器中找到,但不是在你的设备中。

编辑 - 您的设备是The 魅族M3采用联发科MT6750处理器,具有8个ARM Cortex-A53,64位CPU内核和Mali-T860图形。所以这不应该是你的问题。

https://liliputing.com/2016/04/meizu-m3-is-an-octa-core-64-bit-smartphone-for-92.html

您将能够找到的有关该位置的详细信息:

https://github.com/realm/realm-java/issues/705

+0

我无法在/data/app/com.example.opimand.simplesqlite-2/lib/arm64上找到目录,但在手机上安装了应用程序 – Opimand

+0

因此,您应该先检查一下是你的脚本中正确的路径和改变。您可以安装文件管理器来检查这一点。 –

+0

我没有在代码中指定数据库应存储在哪个文件夹中,在其他设备上一切正常。 文件管理器是AndroidStudio的插件吗? – Opimand

0

你错误地定义你的数据库路径。您的数据库将驻留在应用程序包目录中的数据库文件夹中。

应该

/data/data/com.example.opimand.simplesqlite-2/databases/ 
+0

安装在设备上的应用程序,但我找不到他的文件夹。 在其他设备上一切正常 – Opimand

相关问题