所有代码工作正常:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.activity_contacts_detail_row_layout, parent, false);
ImageView smsLogo = (ImageView) row.findViewById(R.id.sms_logo);
smsLogo.setClickable(true);
smsLogo.setTag(position);
if (contactsRow.isSMSApproved == true) smsLogo.setImageResource(R.drawable.messages_green);
else smsLogo.setImageResource(R.drawable.messages_red);
直到那一行:
smsLogo.setImageResource(....)
日志猫:
10-29 22:46:34.006: E/AndroidRuntime(935): java.lang.NullPointerException 10-29 22:46:34.006: E/AndroidRuntime(935): at com.callsfreecalls.android.ContactsDetailArrayAdapter.getView(ContactsDetailArrayAdapter. java:107) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.widget.AbsListView.obtainView(AbsListView.java:1409) 10-29 22:46:34.006: E/AndroidRuntime(935) : 在 android.widget.ListView.measureHeightOfChildren(ListView.java:1216) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.widget.ListView.onMeasure(ListView.java:1127) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.view.View.measure(View.java:8313) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.widget.RelativeLayout .measureChild(RelativeLayout.java:566) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.widget。RelativeLayout.onMeasure(RelativeLayout.java:381) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.view.View.measure(View.java:8313) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.widget.FrameLayout.onMeasure(FrameLayout.java :250) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.view.View.measure(View.java:8313) 10-29 22:46:34.006: E/AndroidRuntime(935):在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.widget.FrameLayout.onMeasure(FrameLayout.java:250) 10-29 22 :46:34.006:E / AndroidRuntime(935):在android.view.View.measure(View.java:8313)10-29 22:46:34.006:E / AndroidRuntime(935):在android。view.ViewRoot.performTraversals(ViewRoot.java:839) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.view.ViewRoot.handleMessage(ViewRoot.java:1859) 10-29 22:46: 34.006: E/AndroidRuntime(935): 在 android.os.Handler.dispatchMessage(Handler.java:99) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.os.Looper.loop(Looper .java:130) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 android.app.ActivityThread.main(ActivityThread.java:3683) 10-29 22:46:34.006: E/AndroidRuntime(935 ): 在 java.lang.reflect.Method.invokeNative(Native Method) 10-29 22:46:34.006: E/AndroidRuntime(935): 在 java.lang.reflect.Method.invoke(Method.java:507) 10 -29 22:46:34.006: E/AndroidRuntime(935): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 10-29 22:46:34.006: E/AndroidRuntime(935 ): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
行布局:
<ImageView
android:id="@+id/sms_logo"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="6dip"
android:src="@drawable/messages_green" />
<ImageView
android:id="@+id/callLogo"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="60dp"
android:layout_marginTop="-60dp"
android:src="@drawable/callbuttonred" />
<TextView
android:id="@+id/contactsDetailData"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="120dp"
android:layout_marginTop="-43dp"
android:gravity="center"
android:shadowColor="#FFFFFFFF"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="1"
android:text="+380674878717"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FF64396F" />
这是代码创建:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts_detail);
bar = ((ProgressBar) findViewById(R.id.progressContactDetailsUpdate));
bar.setVisibility(View.VISIBLE);
contactsDetailsForUsing = this;
adapterDetails = new ContactsDetailArrayAdapter(getApplicationContext(), R.layout.activity_contacts_detail_row_layout);
lvContactDetails = (ListView) findViewById(R.id.listContactsDetailView);
lvContactDetails.setAdapter(adapterDetails);