猿问

Sqlite+Recyclerview ,应用已停止

我想创建一个可以从数据库中检索数据的 recyclerview,并一步一步地跟随这个视频。当我试图运行它时,应用程序“已停止”。我不知道我哪里出错了。请帮忙。


活动_main.xml


xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity"

android:padding="16dp">


<EditText

    android:id="@+id/edittext_name"

    android:layout_width="match_parent"

    android:layout_height="wrap_content" />


<TextView

    android:id="@+id/textviewamount"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_below="@+id/edittext_name"

    android:layout_centerHorizontal="true"

    android:text="0"

    android:textSize="50sp"

    android:layout_marginTop="8dp"

    />


<Button

    android:id="@+id/button_decrease"

    android:layout_width="50dp"

    android:layout_height="72dp"

    android:layout_alignTop="@+id/textviewamount"

    android:layout_toStartOf="@+id/textviewamount"

    android:layout_toLeftOf="@+id/textviewamount"

    android:text="-" />


<Button

    android:id="@+id/button_increase"

    android:layout_width="50dp"

    android:layout_height="72dp"

    android:layout_alignTop="@+id/textviewamount"

    android:layout_toEndOf="@+id/textviewamount"

    android:layout_toRightOf="@+id/textviewamount"

    android:text="+" />


<Button

    android:id="@+id/button_add"

    android:layout_width="wrap_content"

    android:layout_height="72dp"

    android:layout_alignEnd="@+id/edittext_name"

    android:layout_alignRight="@+id/edittext_name"

    android:layout_alignTop="@+id/textviewamount" />


<android.support.v7.widget.RecyclerView

    android:id="@+id/recyclerview"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:layout_below="@+id/button_decrease"

    android:layout_centerHorizontal="true">


</android.support.v7.widget.RecyclerView>


慕田峪4524236
浏览 194回答 2
2回答

红糖糍粑

在双 qots 中 INTEGER 前添加空格&nbsp;&nbsp;&nbsp;&nbsp;GroceryEntry._ID&nbsp;+&nbsp;"&nbsp;INTEGER&nbsp;PRIMARY&nbsp;KEY&nbsp;AUTOINCREMENT,&nbsp;"

天涯尽头无女友

看起来您的 CREATE 子句缺少列名及其类型之间的空格。尝试在列 ID 后添加一个空格,如下所示:GroceryEntry._ID&nbsp;+&nbsp;"&nbsp;INTEGER&nbsp;PRIMARY&nbsp;KEY&nbsp;AUTOINCREMENT,&nbsp;"就在关键字“INTEGER”之前。对其他行执行相同操作。
随时随地看视频慕课网APP

相关分类

Java
我要回答