edittext フィールドに連絡先ピッカーを入力しようとしていたところ、すでに利用可能な非常に多くのリンクを試しました。しかし、私には理解するのが難しいです。edittext フィールドとボタンがある私のアクティビティは次のとおりです。ボタンをクリックすると連絡先が開きます。しかし、ボタンを選択すると、編集テキストフィールドに入力できません。私を助けてください。前もって感謝します。また、これは実行しようとしたときに強制終了されました。丸太猫
at dalvik.system.NativeStart.main(Native Method)
ここで私を助けてください。これはアクティビティ コードです。
package com.sach.droidclinic;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
//import android.provider.;
import android.support.v4.app.NavUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class SaveNum extends Activity {
public Button SaveButton,contactButton1,contactButtton2,contactButton3;
EditText editText11;
private SharedPreferences savednotes1;
private static final int CONTACT_PICKER_RESULT = 1001;
private static final String DEBUG_TAG = null;
TextView disp;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_save_num);
SaveButton = (Button) findViewById(R.id.bt_savedb);
editText11 = (EditText) findViewById(R.id.et_first);
savednotes1 = getSharedPreferences("notes",MODE_PRIVATE);
contactButton1= (Button)findViewById(R.id.contact_button1);
contactButton1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
try {
doLaunchContactPicker(view);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void doLaunchContactPicker(View view) {
// TODO Auto-generated method stub
//@SuppressWarnings("deprecation")
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
}
});
}
@SuppressLint("NewApi")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
disp= (TextView)findViewById(R.id.tv_printmsg);
if (data != null) {
Uri uri = data.getData();
if (uri != null) {
Cursor c = null;
try {
c = getContentResolver().query(uri, new String[]{
ContactsContract.CommonDataKinds.Phone.NUMBER },null,
null, null, null);
if (c != null && c.moveToFirst()) {
String number = c.getString(0);
//Hint type = c.getInt(1);
disp.setText("Your score is " + number);
}
} finally {
if (c != null) {
c.close();
}
}
}
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.save_num, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
完全な logcat は次のとおりです。
`02-09 03:18:25.351: D/dalvikvm(21404): GC_EXTERNAL_ALLOC freed 49K, 49% free 2774K/5379K, external 408K/517K, paused 169ms
02-09 03:18:30.875: W/dalvikvm(21404): VFY: unable to resolve virtual method 4644: Lcom/sach/droidclinic/SaveNum;.getActionBar ()Landroid/app/ActionBar;
02-09 03:18:30.875: D/dalvikvm(21404): VFY: replacing opcode 0x6e at 0x0006
02-09 03:18:30.875: D/dalvikvm(21404): VFY: dead code 0x0009-000d in Lcom/sach/droidclinic/SaveNum;.setupActionBar ()V
02-09 03:18:30.875: W/dalvikvm(21404): VFY: unable to resolve virtual method 133: Landroid/content/ContentResolver;.query (Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Landroid/os/CancellationSignal;)Landroid/database/Cursor;
02-09 03:18:30.875: D/dalvikvm(21404): VFY: replacing opcode 0x74 at 0x0024
02-09 03:18:30.875: D/dalvikvm(21404): VFY: dead code 0x0027-004d in Lcom/sach/droidclinic/SaveNum;.onActivityResult (IILandroid/content/Intent;)V
02-09 03:18:58.265: W/dalvikvm(21687): VFY: unable to resolve virtual method 4644: Lcom/sach/droidclinic/SaveNum;.getActionBar ()Landroid/app/ActionBar;
02-09 03:18:58.265: D/dalvikvm(21687): VFY: replacing opcode 0x6e at 0x0006
02-09 03:18:58.265: D/dalvikvm(21687): VFY: dead code 0x0009-000d in Lcom/sach/droidclinic/SaveNum;.setupActionBar ()V
02-09 03:18:58.265: W/dalvikvm(21687): VFY: unable to resolve virtual method 133: Landroid/content/ContentResolver;.query (Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Landroid/os/CancellationSignal;)Landroid/database/Cursor;
02-09 03:18:58.265: D/dalvikvm(21687): VFY: replacing opcode 0x74 at 0x0024
02-09 03:18:58.265: D/dalvikvm(21687): VFY: dead code 0x0027-004d in Lcom/sach/droidclinic/SaveNum;.onActivityResult (IILandroid/content/Intent;)V
02-09 03:18:58.328: D/AndroidRuntime(21687): Shutting down VM
02-09 03:18:58.328: W/dalvikvm(21687): threadid=1: thread exiting with uncaught exception (group=0x40018578)
02-09 03:18:58.343: E/AndroidRuntime(21687): FATAL EXCEPTION: main
02-09 03:18:58.343: E/AndroidRuntime(21687): java.lang.NoSuchMethodError: android.content.ContentResolver.query
02-09 03:18:58.343: E/AndroidRuntime(21687): at com.sach.droidclinic.SaveNum.onActivityResult(SaveNum.java:73)
02-09 03:18:58.343: E/AndroidRuntime(21687): at android.app.Activity.dispatchActivityResult(Activity.java:3908)
02-09 03:18:58.343: E/AndroidRuntime(21687): at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
02-09 03:18:58.343: E/AndroidRuntime(21687): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2111)
02-09 03:18:58.343: E/AndroidRuntime(21687): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
02-09 03:18:58.343: E/AndroidRuntime(21687): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
02-09 03:18:58.343: E/AndroidRuntime(21687): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-09 03:18:58.343: E/AndroidRuntime(21687): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
02-09 03:18:58.343: E/AndroidRuntime(21687): at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 03:18:58.343: E/AndroidRuntime(21687): at android.os.Looper.loop(Looper.java:130)
02-09 03:18:58.343: E/AndroidRuntime(21687): at android.app.ActivityThread.main(ActivityThread.java:3687)
02-09 03:18:58.343: E/AndroidRuntime(21687): at java.lang.reflect.Method.invokeNative(Native Method)
02-09 03:18:58.343: E/AndroidRuntime(21687): at java.lang.reflect.Method.invoke(Method.java:507)
02-09 03:18:58.343: E/AndroidRuntime(21687): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
02-09 03:18:58.343: E/AndroidRuntime(21687): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
02-09 03:18:58.343: E/AndroidRuntime(21687): at dalvik.system.NativeStart.main(Native Method)