문제

나는 사용자 정의 대화 상자에서 빠른 연락처 배지를 사용하려고합니다.나는 품질 관리를 수정하려고 할 때,항상 충돌,하지만 난 이유를 찾을 수 없습니다.아무도 도울 수 있습니까?미리 감사드립니다.

사용자 정의2015 년:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<QuickContactBadge 
android:id="@+id/quickContactBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/quick_contact_badge"
android:padding="5dp"
></QuickContactBadge>
</RelativeLayout>

자바 코드:

Dialog dialog = new Dialog(NameOfActivity.this);
dialog.setContentView(R.layout.custom_xml);
dialog.show();

QuickContactBadge qcb = (QuickContactBadge) findViewById (R.id.quickContactBadge); 
//This make app always crash
qcb.setMode(ContactsContract.QuickContact.MODE_LARGE); 
qcb.assignContactFromPhone("12345678", true);  
qcb.setImageResource(R.drawable.icon);
도움이 되었습니까?

해결책

당신은 점점 해야 합니다 NullPointerException.전화 findViewById() 대화 상자 개체에서.

QuickContactBadge qcb = (QuickContactBadge) 
                                 dialog.findViewById (R.id.quickContactBadge);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top