没有这样的表:MESSAGES(代码1):

时间:2017-01-26 16:11:36

标签: android sqlite sugarorm

我收到一个名为“没有这样的表”的错误。此错误以前没有。我正在使用Sugar ORM for SQLite Database。我尝试重新安装应用程序,但这不起作用。

Messages.class

import com.orm.SugarRecord;



public class Messages extends SugarRecord {
    String senderId;
    String receiverId;
    String message;


public Messages(){

}

public Messages(String senderId, String receiverId, String message) {
    this.message = message;
    this.senderId = senderId;
    this.receiverId = receiverId;
}

public void setMessage(String message) {
    this.message = message;
}
public void setSenderId(String senderId) {
    this.senderId = senderId;
}
public void setReceiverId(String receiverId) {
    this.receiverId = receiverId;
}


public String getMessage(){
    return message;
}
public String getSenderId(){
    return senderId;
}
public String getReceiverId() {
    return receiverId;
}

}

存储数据

public void send(View view) {
    channel.sendUserMessage(sendText.getText().toString(), new BaseChannel.SendUserMessageHandler() {
        @Override
        public void onSent(UserMessage userMessage, SendBirdException e) {
            if (e != null) {
                // Error.
                Log.d("Error", "MSG not sent");
                return;
            }
            Messages messages = new Messages(sender, receiver, userMessage.getMessage());
            messages.save();
            sentText.setText(sendText.getText().toString());
        }
    });
}

logcat的

  android.database.sqlite.SQLiteException: no such table: MESSAGES (code 1): , while compiling: INSERT OR REPLACE INTO MESSAGES(ID,SENDER_ID,RECEIVER_ID,MESSAGE) VALUES (?,?,?,?)                                                                  
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1093)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:670)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at  android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1607)
at com.orm.SugarRecord.save(SugarRecord.java:266)
at com.orm.SugarRecord.save(SugarRecord.java:360)
at loany.gmx.com.sendbirdchat.GroupChannelActivity$2.onSent(GroupChannelActivity.java:89)
at com.sendbird.android.BaseChannel$8$1.run(BaseChannel.java:466)

清单文件

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<uses-permission android:name="com.loany.gmx.sendbirdloany.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name="com.orm.SugarApp">

    <meta-data android:name="DATABASE" android:value="sugar_chat.db" />
    <meta-data android:name="VERSION" android:value="2" />
    <meta-data android:name="QUERY_LOG" android:value="true" />
    <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="loany.gmx.com.sendbirdchat" />

    <activity android:name=".LoginActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".ListUsersActivity" />
    <activity android:name=".GroupChannelActivity"></activity>
</application>

1 个答案:

答案 0 :(得分:0)

您需要在SugarApp中指定AndroidManifest.xml作为您的应用类。您可以通过更改android:name代码的application属性来实现此目的。

请检查:Getting started with Sugar ORM

如果问题仍然存在,请尝试这些,

  • 尝试禁用即时运行
  • 尝试从AndroidManifest文件中删除这些行:

的AndroidManifest.xml

<meta-data android:name="DATABASE" android:value="sugar_chat.db" />
<meta-data android:name="VERSION" android:value="2" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="loany.gmx.com.sendbirdchat" />