getViewでlayoutInflater.inflateした際のエラー
Fragment内にListViewを配置しているのですが、Android4.x環境で以下のエラーが発生します(Android6.xでは問題なし)。解決法を探しても似た事例が見つかりませんでした。よろしくお願いします。
E/AndroidRuntime: FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #7: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at {MyPackageName}.CustomAdapter.getView(CustomAdapter.java:36)
at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
at android.widget.AbsListView.obtainView(AbsListView.java:2271)
at android.widget.ListView.makeAndAddView(ListView.java:1769)
at android.widget.ListView.fillDown(ListView.java:672)
at android.widget.ListView.fillFromTop(ListView.java:733)
at android.widget.ListView.layoutChildren(ListView.java:1622)
at android.widget.AbsListView.onLayout(AbsListView.java:2106)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:598)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1759)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:435)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1868)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1689)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x1010433 a=-1}
at android.content.res.Resources.loadColorStateList(Resources.java:
CustomAdapterのコードは以下です。
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
public class CustomAdapter extends ArrayAdapter<Article> {
private LayoutInflater layoutInflater_;
Context context;
List<Article> articles;
public CustomAdapter(Context context, int textViewResourceId, List<Article> objects) {
super(context, textViewResourceId, objects);
this.context = context;
this.articles = objects;
layoutInflater_ = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
Article item = articles.get(position);
// convertViewがnullの時のみ作成
if (v == null) {
v = layoutInflater_.inflate(R.layout.row, null); //←ここでエラー
}
TextView textView = (TextView)convertView.findViewById(R.id.textView2);
textView.setText(item.getTitle());
TextView textView1 = (TextView)convertView.findViewById(R.id.textView3);
textView1.setText(item.getSite());
TextView textView2 = (TextView)convertView.findViewById(R.id.textView4);
textView2.setText(item.getDate());
return v;
}
}
-追記-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView3"
android:layout_below="@+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="?android:attr/colorPrimary"
android:textAllCaps="false"
android:fontFamily="sans-serif" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView4"
android:layout_alignTop="@+id/textView3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#505050" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#000000" />
</RelativeLayout>