如何在sqljavaandroid中插入字符串

cl25kdpy  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(214)

我想添加字符串到sql数据库javaandroid,我有while循环从手机获取联系人
当我插入字符串时,应用程序崩溃了
我的密码是

public void getContactList() {
    ContentResolver cr = getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
            null, null, null, null);

if ((cur != null ? cur.getCount() : 0) > 0) {
    while (cur != null && cur.moveToNext()) {
        String id = cur.getString(
                cur.getColumnIndex(ContactsContract.Contacts._ID));
        String name = cur.getString(cur.getColumnIndex(
                ContactsContract.Contacts.DISPLAY_NAME));

        if (cur.getInt(cur.getColumnIndex(
                ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
            Cursor pCur = cr.query(
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                    null,
                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
                    new String[]{id}, null);
            while (pCur.moveToNext()) {
                String phoneNo = pCur.getString(pCur.getColumnIndex(
                        ContactsContract.CommonDataKinds.Phone.NUMBER));
                Log.i("jslkjclk",name+"\n"+phoneNo);
//the app crashes here
                sqLiteDatabase.execSQL("INSERT INTO Contacts (name,number) VALUES ('"+name+"','"+phoneNo+"')");
                sharedPreferences.edit().putString("IfContact","2").apply();
                contactIf=sharedPreferences.getString("IfContact","");
            }
            pCur.close();
        }
    }
}
if(cur!=null){
    cur.close();
}
}

请任何人帮帮我
我的logcat

11-23 22:57:25.812 12599-12599/? I/art: Late-enabling -Xcheck:jni
11-23 22:57:25.930 12599-12599/com.example.importantmessageonly W/System: ClassLoader referenced unknown path: /data/app/com.example.importantmessageonly-2/lib/arm64
11-23 22:57:26.090 12599-12599/com.example.importantmessageonly W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
11-23 22:57:26.207 12599-12599/com.example.importantmessageonly I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
11-23 22:57:26.207 12599-12599/com.example.importantmessageonly I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
11-23 22:57:26.406 12599-12599/com.example.importantmessageonly I/jslkjclk: no
11-23 22:57:26.444 12599-12599/com.example.importantmessageonly I/jslkjclk: Hassan
    01020499918
11-23 22:57:26.782 12599-12599/com.example.importantmessageonly I/Process: Sending signal. PID: 12599 SIG: 9

这是我的全部日志,因为我在物理设备上工作

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题