0

setadapter 関数が呼び出されるたびにアプリがクラッシュし続けますが、その理由がわかりません。誰か助けてもらえますか? 私が実行しているエミュレーターは、アプリが予期せず停止したとだけ言っています。

これが私のメインです

public class MainActivity extends Activity {

    private ListView listView1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Ride ride_data[] = new Ride[]
        {
                new Ride("LA Trip", "la man"),
                new Ride("SD Trip", "sd man"),
                new Ride("SF Trip", "sf man")
        };

        RideAdapter adapter = new RideAdapter(this,
                R.layout.listview_item_row,ride_data);

        listView1 = (ListView)findViewById(R.id.listView1);

        View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
        listView1.addHeaderView(header);

        listView1.setAdapter(adapter);

    }

}

これが私のアダプターです

public class RideAdapter extends ArrayAdapter<Ride>{

    Context context;
    int layoutResourceId;
    Ride data[] = null;

    public RideAdapter(Context context, int layoutResourceId, Ride[] data)
    {
        super(context,layoutResourceId,data);
        this.context = context;
        this.layoutResourceId = layoutResourceId;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View row = convertView;
        RideHolder holder = null;

        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new RideHolder();
            holder.rideName = (TextView)row.findViewById(R.id.txtRideName);
            holder.personName = (TextView)row.findViewById(R.id.txtPersonName);

            row.setTag(holder);
        }
        else
        {
            holder = (RideHolder)row.getTag();
        }

        Ride ride = data[position];
        holder.rideName.setText(ride.rideName);
        holder.personName.setText(ride.personName);

        return row;

    }

    public static class RideHolder
    {
        TextView rideName;
        TextView personName;
    }
}

これは私のライドクラスです

public class Ride {
    public String rideName;
    public String personName;

    public Ride()
    {

    }

    public Ride(String rideName, String personName)
    {
        super();
        this.rideName=rideName;
        this.personName=personName;
    }
}

そして最後に、これは私のリストアイテムビューです

<?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="fill_parent"
    android:orientation="vertical"
    android:padding="10dp"
     >

    <Textview
        android:id="@+id/txtRideName"
        android:layout_width ="wrap_content"
        android:layout_height="fill_parent"
        android:gravity="center_horizontal"
        />
    <Textview
        android:id="@+id/txtPersonName"
        android:layout_width ="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        />

</LinearLayout>

どんな助けでも大歓迎です!

4

1 に答える 1

1
    <Textview
            android:id="@+id/txtRideName"
            android:layout_width ="wrap_content"
            android:layout_height="fill_parent"
            android:gravity="center_horizontal"
            />
    <Textview
            android:id="@+id/txtPersonName"
            android:layout_width ="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            />

Textview は、Textview ではなく TextView である必要があります。

logcat で Crash を読む方法を学ぶ必要があります。

android.view.InflateException: バイナリ XML ファイルの行 #8: クラス Textview の拡張中にエラーが発生しました

    05-03 11:18:29.399: E/AndroidRuntime(12890): FATAL EXCEPTION: main
    05-03 11:18:29.399: E/AndroidRuntime(12890): android.view.InflateException: Binary XML file line #8: Error inflating class Textview
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at com.example.hello1.RideAdapter.getView(RideAdapter.java:30)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.AbsListView.obtainView(AbsListView.java:2468)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.ListView.makeAndAddView(ListView.java:1775)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.ListView.fillDown(ListView.java:678)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.ListView.fillFromTop(ListView.java:739)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.ListView.layoutChildren(ListView.java:1628)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.AbsListView.onLayout(AbsListView.java:2303)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.View.layout(View.java:14063)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.ViewGroup.layout(ViewGroup.java:4655)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.View.layout(View.java:14063)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.ViewGroup.layout(ViewGroup.java:4655)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.View.layout(View.java:14063)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.ViewGroup.layout(ViewGroup.java:4655)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.View.layout(View.java:14063)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.ViewGroup.layout(ViewGroup.java:4655)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.View.layout(View.java:14063)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.ViewGroup.layout(ViewGroup.java:4655)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2017)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1838)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1131)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4611)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.Choreographer.doFrame(Choreographer.java:525)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.os.Handler.handleCallback(Handler.java:615)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.os.Handler.dispatchMessage(Handler.java:92)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.os.Looper.loop(Looper.java:137)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.app.ActivityThread.main(ActivityThread.java:4898)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at java.lang.reflect.Method.invokeNative(Native Method)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at java.lang.reflect.Method.invoke(Method.java:511)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at dalvik.system.NativeStart.main(Native Method)
    05-03 11:18:29.399: E/AndroidRuntime(12890): Caused by: java.lang.ClassNotFoundException: android.view.Textview
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.LayoutInflater.createView(LayoutInflater.java:552)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
    05-03 11:18:29.399: E/AndroidRuntime(12890):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
于 2013-05-03T03:25:48.203 に答える