android - Adaptador de vista de lista personalizado NullPointerException
listview baseadapter (1)
Hola comunidad de stackoverflow,
Obtengo un NPE en mi método getView de mi clase de adaptador personalizado que extiende BaseAdapter. Espero que puedas ayudarme.
Aquí está mi método getView:
@Override
public View getView(int pos, View convertView, ViewGroup viewGroup) {
if(convertView==null){
LayoutInflater inflater = (LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row, null);
}
TextView datetv = (TextView) convertView.findViewById(R.id.date);
TextView valuetv = (TextView) convertView.findViewById(R.id.value);
TextView cattv = (TextView) convertView.findViewById(R.id.cat);
if(values.get(pos)>VALUE_MIN&&values.get(pos)<VALUE_MAX){
datetv.setTextColor(context.getResources().getColor(R.color.Good));
valuetv.setTextColor(context.getResources().getColor(R.color.Good));
cattv.setTextColor(context.getResources().getColor(R.color.Good));
}
else{
datetv.setTextColor(context.getResources().getColor(R.color.Bad));
valuetv.setTextColor(context.getResources().getColor(R.color.Bad));
cattv.setTextColor(context.getResources().getColor(R.color.Bad));
}
datetv.setText(dates.get(pos));
valuetv.setText(Double.toString(values.get(pos)));
cattv.setText(cats.get(pos));
LinearLayout l = (LinearLayout) convertView.findViewById(R.id.notelayout);
l.setFocusableInTouchMode(false);
l.setFocusable(false);
l.setOnClickListener(this);
l.setId(pos);
return convertView;
}
Esto es row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="140dip"
android:layout_height="wrap_content"
android:padding="4dip"
>
<TextView
android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="24dip"
android:textSize="15dip"
android:gravity="left" android:paddingLeft="6dip"
android:layout_weight="1" />
<TextView
android:id="@+id/cat"
android:layout_width="fill_parent"
android:layout_height="24dip"
android:textSize="15dip"
android:gravity="left" android:paddingLeft="6dip"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dip"
>
<TextView
android:id="@+id/value"
android:layout_width="fill_parent"
android:layout_height="48dip"
android:textSize="40dip"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/notelayout"
android:orientation="vertical"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_gravity="center"
android:padding="4dip"
>
<ImageView
android:id="@+id/note"
android:layout_width="wrap_content"
android:layout_height="48dip"
android:gravity="center"
android:src="@drawable/papiertje"
android:scaleType="centerInside"/>
</LinearLayout>
</LinearLayout>
Y este es el error que estoy recibiendo:
01-30 00:34:31.772: ERROR/AndroidRuntime(497): FATAL EXCEPTION: main
01-30 00:34:31.772: ERROR/AndroidRuntime(497): java.lang.NullPointerException
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at com.yellos.android.glucose.ListViewAdapter.getView(ListViewAdapter.java:85)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.AbsListView.obtainView(AbsListView.java:1294)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.ListView.onMeasure(ListView.java:1109)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.View.measure(View.java:8171)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:696)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.LinearLayout.onMeasure(LinearLayout.java:306)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.View.measure(View.java:8171)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.View.measure(View.java:8171)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.View.measure(View.java:8171)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.View.measure(View.java:8171)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.os.Looper.loop(Looper.java:123)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at java.lang.reflect.Method.invokeNative(Native Method)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at java.lang.reflect.Method.invoke(Method.java:521)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-30 00:34:31.772: ERROR/AndroidRuntime(497): at dalvik.system.NativeStart.main(Native Method)
La línea 85 es l.setFocusableInTouchMode(false);
Elimine la condición de comprobación de convertView == null en getView ()
Escriba el código de inflado del diseño directamente sin encerrar adentro si