No such table (code 1) - ver: 1.5 - Android Studio 2.0 RC3
See original GitHub issueHi,
I am using Android Studio 2.0 (RC3) version with gradle:2.0.0-rc3. SugarORM version is 1.5 added as gradle dependency.
Application is crashing on start since i have data writing/reading once the application starts. In my Application class, i am not extending SugarApp, since i am using another module which needs to be extended. Instead, i am initializing SugarContext.
public class MyApplication extends AnotherApplication implements Injector {
@Override
public void onCreate() {
super.onCreate();
SugarContext.init(this);
}
public SQLiteDatabase getDatabase() {
return openOrCreateDatabase(getString(R.string.database_name), getApplicationContext().MODE_PRIVATE, null);
}
@Override
public void onTerminate() {
super.onTerminate();
SugarContext.terminate();
}
}
I have only two tables for my app and i am trying to create them during SplashScreen.
public class SplashScreenActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
InitApp();
}
private void InitApp()
{
initSugarOrm();
}
private void initSugarOrm() {
((MyApplication)getApplication()).getDatabase();
MoodTrackerTable.findById(MoodTrackerTable.class, (long) 1);
QuizQuestionTable dummyQuiz = new QuizQuestionTable();
dummyQuiz.save();
QuizQuestionTable.delete(dummyQuiz);
QuizQuestionTable.findById(QuizQuestionTable.class, (long) 1);
}
}
These are my models:
@Table(name = "MoodTrackerTable")
public class MoodTrackerTable extends SugarRecord {
public static final String SHOW_DATE_PATTERN = "dd.MM";
public static final String DATE_TODAY = "today";
public static final String DATE_YESTERDAY = "yesterday";
private long id;
@Column(name = "date_time_stamp")
public long dateTimeStamp;
public int rate;
public MoodTrackerTable() { }
public String getDateFormatted() {
DateTime dbTimeStamp = new DateTime(dateTimeStamp);
DateTime yesterday = DateTime.now().withTimeAtStartOfDay().minusDays(1);
if (DateTime.now().getDayOfYear() == dbTimeStamp.getDayOfYear()) {
return DATE_TODAY;
} else if (dbTimeStamp.isAfter(yesterday)) {
return DATE_YESTERDAY;
}
return dbTimeStamp.toString(SHOW_DATE_PATTERN);
}
public Long getId() {
return id;
}
}
@Table(name = "QuizQuestionTable")
public class QuizQuestionTable extends SugarRecord {
private long id;
private String question;
private String right;
private String wrong1;
private String wrong2;
public QuizQuestionTable() {
}
public QuizQuestionTable(QuizQuestionModel model) {
question = model.question;
right = model.right;
wrong1 = model.wrong1;
wrong2 = model.wrong2;
}
public QuizQuestionModel toQuizQuestionModel() {
QuizQuestionModel result = new QuizQuestionModel();
result.question = question;
result.right = right;
result.wrong1 = wrong1;
result.wrong2 = wrong2;
return result;
}
public Long getId() {
return id;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getRight() {
return right;
}
public void setRight(String right) {
this.right = right;
}
public String getWrong1() {
return wrong1;
}
public void setWrong1(String wrong1) {
this.wrong1 = wrong1;
}
public String getWrong2() {
return wrong2;
}
public void setWrong2(String wrong2) {
this.wrong2 = wrong2;
}
}
Both models are contained in package clientdomain.data.database.
At the end, these are MANIFEST entries regarding Sugar:
<meta-data
android:name="DATABASE"
android:value="@string/database_name"/>
<meta-data
android:name="VERSION"
android:value="1"/>
<meta-data
android:name="QUERY_LOG"
android:value="true"/>
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="clientdomain.data.database" />
Stack trace does not show much details:
Caused by: android.database.sqlite.SQLiteException: no such table: MoodTrackerTable (code 1): ,
while compiling: SELECT * FROM MoodTrackerTable WHERE id=? LIMIT 1
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1240)
at com.orm.SugarRecord.find(SugarRecord.java:201)
at com.orm.SugarRecord.findById(SugarRecord.java:135)
at clientdomain.activity.SplashScreenActivity.initSugarOrm(SplashScreenActivity.java:75)
at clientdomain.activity.SplashScreenActivity.InitApp(SplashScreenActivity.java:36)
at clientdomain.activity.SplashScreenActivity.onCreate(SplashScreenActivity.java:31)
Ofcourse, i have cleared cache, data, uninstalled application, cleared project, rebuild it… Fresh start and crash.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
android.database.sqlite.SQLiteException: no such table: (code ...
After spending couple of hours I got this solution: 1) Settings > Application Manager. 2) Select App.
Read more >Caused by android database sqlite SQLiteException no such ...
For the majority of customers, it is functioning properly, but a small number are encountering the Caused by: android.database.sqlite.
Read more >Meet Android Studio | Android Developers
On top of IntelliJ's powerful code editor and developer tools, ... res: Contains all non-code resources, such as XML layouts, UI strings, and...
Read more >Kotlin Language Documentation 1.7.21
Android Studio. Eclipse. Compatibility with the Kotlin language versions. Other IDEs support. What's next? Migrate to Kotlin code style.
Read more >[Developer Preview Android P] SQLiteException: no such ...
* What was the actual result? android.database.sqlite.SQLiteException: no such table: StateProvinceDB (code 1 SQLITE_ERROR): , while compiling: SELECT DISTINCT ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@JonatanSalas With the release of Android Studio 2, this is enabled by default. Perhaps it justifies a 1.5.1 fix release.
You are welcome! Glad to support you!