android7.0模拟器调试,android
我正在开发将联系人保存在.vcf文件中的应用程序。 当我运行模拟器来测试应用程序时,我还会收到以下错误。 应用程序正在物理设备上运行。 但是android 7.0及更高版本的模拟器也给出了错误。 (警告:模拟器在Android 6.0中不会失败)
cursor()在logcat中似乎有错误。 但是它说“ dlopen失败了”。 请查看logcat。 可能是什么原因?
我使用GenyMotion作为模拟器。
提前致谢。
我的活动:
public class MainActivity extends AppCompatActivity {
Button Backup_Button;
Cursor cursor;
ArrayList vCard ;
String vfile, vcardstring;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Backup_Button = findViewById(R.id.Backup_Button);
vfile = "Contacts" + "_" + System.currentTimeMillis()+".vcf";
Backup_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getVcardString();
Toast.makeText(MainActivity.this, "clickeddddd", Toast.LENGTH_SHORT).show();
}
});
}
private void getVcardString() {
// TODO Auto-generated method stub
vCard = new ArrayList();
cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
if(cursor!=null&&cursor.getCount()>0){
cursor.moveToFirst();
for(int i =0;i
get(cursor);
Log.d("TAG", "Contact "+(i+1)+"VcF String is"+vCard.get(i)); //(MainActivity.java:62) --- Caution: LogCat Error Line
cursor.moveToNext();
}
cursor.close();
}
else
{
Log.d("TAG", "No Contacts in Your Phone");
Toast.makeText(this, "NO CONTACTSSSSSSSSSSSSSSSSSSSSS", Toast.LENGTH_SHORT).show();
}
}
public void get(Cursor cursor){
String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
AssetFileDescriptor fd;
try {
fd = this.getContentResolver().openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();
byte[] buf = new byte[(int) fd.getDeclaredLength()];
fis.read(buf);
vcardstring = new String(buf);
vCard.add(vcardstring);
//Save contacts to storage
} catch (Exception e1){
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
我的LogCat:
2019-08-13 01:14:12.420 1811-2814/android.process.acore E/VCardComposer: Cursor#moveToNext() returned false
2019-08-13 01:14:12.453 2840-2840/com.androidcontactbackup E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.androidcontactbackup, PID: 2840
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:437)
at com.androidcontactbackup.MainActivity.getVcardString(MainActivity.java:81)
at com.androidcontactbackup.MainActivity.access$000(MainActivity.java:24)
at com.androidcontactbackup.MainActivity$1.onClick(MainActivity.java:64)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24697)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
android7.0模拟器调试,android
我正在开发将联系人保存在.vcf文件中的应用程序。 当我运行模拟器来测试应用程序时,我还会收到以下错误。 应用程序正在物理设备上运行。 但是android 7.0及更高版本的模拟器也给出了错误。 (警告:模拟器在Android 6.0中不会失败)
cursor()在logcat中似乎有错误。 但是它说“ dlopen失败了”。 请查看logcat。 可能是什么原因?
我使用GenyMotion作为模拟器。
提前致谢。
我的活动:
public class MainActivity extends AppCompatActivity {
Button Backup_Button;
Cursor cursor;
ArrayList vCard ;
String vfile, vcardstring;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Backup_Button = findViewById(R.id.Backup_Button);
vfile = "Contacts" + "_" + System.currentTimeMillis()+".vcf";
Backup_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getVcardString();
Toast.makeText(MainActivity.this, "clickeddddd", Toast.LENGTH_SHORT).show();
}
});
}
private void getVcardString() {
// TODO Auto-generated method stub
vCard = new ArrayList();
cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
if(cursor!=null&&cursor.getCount()>0){
cursor.moveToFirst();
for(int i =0;i
get(cursor);
Log.d("TAG", "Contact "+(i+1)+"VcF String is"+vCard.get(i)); //(MainActivity.java:62) --- Caution: LogCat Error Line
cursor.moveToNext();
}
cursor.close();
}
else
{
Log.d("TAG", "No Contacts in Your Phone");
Toast.makeText(this, "NO CONTACTSSSSSSSSSSSSSSSSSSSSS", Toast.LENGTH_SHORT).show();
}
}
public void get(Cursor cursor){
String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
AssetFileDescriptor fd;
try {
fd = this.getContentResolver().openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();
byte[] buf = new byte[(int) fd.getDeclaredLength()];
fis.read(buf);
vcardstring = new String(buf);
vCard.add(vcardstring);
//Save contacts to storage
} catch (Exception e1){
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
我的LogCat:
2019-08-13 01:14:12.420 1811-2814/android.process.acore E/VCardComposer: Cursor#moveToNext() returned false
2019-08-13 01:14:12.453 2840-2840/com.androidcontactbackup E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.androidcontactbackup, PID: 2840
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:437)
at com.androidcontactbackup.MainActivity.getVcardString(MainActivity.java:81)
at com.androidcontactbackup.MainActivity.access$000(MainActivity.java:24)
at com.androidcontactbackup.MainActivity$1.onClick(MainActivity.java:64)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24697)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)