Neu zum Threading. Neu in SQL. Neu, um Kontaktinformationen zu erhalten. Natürlich bin ich verloren. Wenn ich dieses Logcat richtig lese, sagt es mir entweder: Spalte data1 existiert nicht, oder dass ich nach den falschen Informationen suche. Unglücklicherweise war dies ein Lernpfad "lerne von meinen Fehlern" und ich kann das nicht herausfinden. Jede Hilfe wird sehr geschätzt.Logcat sagt "ungültige Spalte data1"
Ziel ist es, den Namen, die Telefonnummer und die E-Mail-Adresse des Kontakts zu erhalten (passende Informationen über Kontakt-ID).
Log:
06-22 21:15:44.700: E/AndroidRuntime(1662): FATAL EXCEPTION: Thread-120
06-22 21:15:44.700: E/AndroidRuntime(1662): java.lang.IllegalArgumentException: Invalid column data1
06-22 21:15:44.700: E/AndroidRuntime(1662): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
06-22 21:15:44.700: E/AndroidRuntime(1662): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
06-22 21:15:44.700: E/AndroidRuntime(1662): at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
06-22 21:15:44.700: E/AndroidRuntime(1662): at android.content.ContentResolver.query(ContentResolver.java:372)
06-22 21:15:44.700: E/AndroidRuntime(1662): at android.content.ContentResolver.query(ContentResolver.java:315)
06-22 21:15:44.700: E/AndroidRuntime(1662): at sat.tuts4mobile.customlistview.ContactDetails$1.run(ContactDetails.java:53)
06-22 21:15:44.700: E/AndroidRuntime(1662): at java.lang.Thread.run(Thread.java:856)
-Code (Es zieht Informationen für den Kontakt ID 0):
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.TextView;
/**
* Created by Pete on 6/19/13.
*/
public class ContactDetails extends Activity {
TextView tvContactName, tvPhoneNum, tvPhoneType, tvPhoneFull,
tvEmailAdd, tvEmailType, tvEmailFull,
tvAddress, tvAddType, tvAddFull;
String contactId, contactName, phoneType, phoneFull, phoneNum1,
emailAdd, emailType, emailFull,
address, addType, addFull;
//Contact List query arguments
Uri uri;
String[] projection, selectionArgs;
String selection, sortOrder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contactinfo);
initialize();
contactId = getIntent().getStringExtra("contactId");
contactName = getIntent().getStringExtra("contactName");
new Thread(new Runnable() {
@Override
public void run() {
uri = ContactsContract.Contacts.CONTENT_URI;
projection = new String[] {
ContactsContract.Data.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
selection = ContactsContract.Data.CONTACT_ID +
" = " + contactId + " AND " +
ContactsContract.Data.MIMETYPE + " = '" +
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'";
selectionArgs = null;
sortOrder = null;
// Create cursor searching for data associated with contactId
if (contactId != null) {
// Return all the PHONE data for the contact
Cursor cursor = getContentResolver().query(
uri, projection, selection, selectionArgs, sortOrder);
//Get the indexes of the required columns
while (cursor.moveToNext()) {
// Extract the name
contactName = cursor.getString(
cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
tvContactName.setText(contactName);
// Extract the phone number
phoneFull = cursor.getString(
cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
tvPhoneFull.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
tvPhoneFull.setText(phoneFull);
}
});
cursor.close();
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
projection = null;
selection = ContactsContract.CommonDataKinds.Email.CONTACT_ID +
" = " + contactId + " AND " +
ContactsContract.Data.MIMETYPE + " = '" +
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE + "'";
selectionArgs = null;
sortOrder = null;
Cursor emailCursor = getContentResolver().query(
uri, projection, selection, selectionArgs, sortOrder);
while (emailCursor.moveToNext()) {
// Extract email address
emailFull = emailCursor.getString(
emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
}
tvPhoneFull.post(new Runnable() {
@Override
public void run() {
tvEmailFull.setText(emailFull);
}
});
emailCursor.close();
}
}).start();
}
public void initialize() {
tvContactName = (TextView)findViewById(R.id.tvContactName);
tvPhoneNum = (TextView)findViewById(R.id.tvPhoneNum);
tvPhoneType = (TextView)findViewById(R.id.tvPhoneType);
tvPhoneFull = (TextView)findViewById(R.id.tvPhoneFull);
tvEmailAdd = (TextView)findViewById(R.id.tvEmailAdd);
tvEmailType = (TextView)findViewById(R.id.tvEmailType);
tvEmailFull = (TextView)findViewById(R.id.tvEmailFull);
tvAddress = (TextView)findViewById(R.id.tvAddress);
tvAddType = (TextView)findViewById(R.id.tvAddType);
tvAddFull = (TextView)findViewById(R.id.tvAddFull);
}
}
Sie möchten vielleicht erläutern, was dieser Code zu erreichen versucht. Sobald Sie dieses Problem überwunden haben, stürzen Sie sich auf 'tvContactName.setText (contactName);', während Sie dies in einem Hintergrund-Thread tun. Ziehen Sie in Betracht, einen 'CursorLoader' oder möglicherweise eine' AsyncTask' zu verwenden, da beide bessere Threading- und UI-Aktualisierungen bieten. – CommonsWare
danke für die Köpfe da oben. Bearbeiten OP jetzt – Psest328