Reputation: 933
I am using ormlite 4.46.
I am getting error, "Caused by: java.lang.IllegalArgumentException: No fields have a DatabaseField annotation in class com.github.snowdream.android.a.a.j" for the following scenario,
/*
* Copyright (C) 2013 Snowdream Mobile <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.snowdream.android.app.downloader;
import android.content.Context;
import android.text.TextUtils;
import android.webkit.URLUtil;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import org.apache.commons.lang3.builder.ToStringBuilder;
/**
* The download task
*
* @author snowdream <[email protected]>
* @version v1.0
* @date Sep 29, 2013
*/
@DatabaseTable(tableName = "downloadtask")
public class DownloadTask extends Object {
@DatabaseField(persisted = false)
private Context context = null;
/**
* the time of finish downloading
*/
@DatabaseField(columnName = "finishTime")
private long finishTime = 0;
/**
* id
*/
@DatabaseField(columnName = "id",generatedId = true, canBeNull = false)
private int id = 0;
@DatabaseField(persisted = false)
private DownloadListener listener = null;
/**
* mimetype
*/
@DatabaseField(columnName = "mimeType")
private String mimeType = "";
/**
* name
*/
@DatabaseField(columnName = "name")
private String name = "";
/**
* the save path on the sdcard
*/
@DatabaseField(columnName = "path",canBeNull = false)
private String path = "";
/**
* total size
*/
@DatabaseField(columnName = "size")
private long size = 0;
/**
* the time of start downloading
*/
@DatabaseField(columnName = "startTime")
private long startTime = 0;
/**
* download status
*/
@DatabaseField(columnName = "status")
private int status = DownloadStatus.STATUS_PENDING;
@DatabaseField(persisted = false)
private AsycDownloadTask task = null;
/**
* type
*/
@DatabaseField(columnName = "type")
private int type = DownloadType.TYPE_UNKNOWN;
/**
* url
*/
@DatabaseField(columnName = "url",canBeNull = false)
private String url = "";
@SuppressWarnings("unused")
private DownloadTask() {
}
public DownloadTask(Context context) {
super();
this.context = context;
}
public DownloadTask(DownloadTask task) {
if (task == null) return;
this.context = task.context;
this.startTime = task.startTime;
this.finishTime = task.finishTime;
this.id = task.id;
this.mimeType = task.mimeType;
this.name = task.name;
this.path = task.path;
this.size = task.size;
this.status = task.status;
this.type = task.type;
this.url = task.url;
this.task = task.task;
this.listener = task.listener;
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
@Override
public int hashCode() {
return url.hashCode();
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
public Context getContext() {
return context;
}
public void setContext(Context context) {
this.context = context;
}
public long getFinishTime() {
return finishTime;
}
public void setFinishTime(long finishTime) {
this.finishTime = finishTime;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public DownloadListener getListener() {
return listener;
}
public void setListener(DownloadListener listener) {
this.listener = listener;
}
public String getMimeType() {
return mimeType;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
/**
* url, name and path is not empty.
*
* @return true is valid,otherwise not.
*/
public boolean isComplete() {
return !TextUtils.isEmpty(url) && !TextUtils.isEmpty(name) && !TextUtils.isEmpty(path);
}
/**
* Check whether the Task is valid.
*
* @return true is valid,otherwise not.
*/
public boolean isValid() {
return URLUtil.isNetworkUrl(url);
}
protected void setDownloadTask(DownloadTask task) {
//this.context = task.context;
this.startTime = task.startTime;
//this.finishTime = task.finishTime;
this.id = task.id;
if (TextUtils.isEmpty(this.mimeType)) {
this.mimeType = task.mimeType;
}
if (TextUtils.isEmpty(this.name)) {
this.name = task.name;
}
if (TextUtils.isEmpty(this.path)) {
this.path = task.path;
}
this.size = task.size;
this.status = task.status;
this.type = task.type;
this.url = task.url;
//this.task = task.task;
//this.listener = task.listener;
}
/**
* Start the Task
*
* @param context Context
* @param listener DownloadListener
*/
@SuppressWarnings({
"rawtypes", "unchecked"
})
protected void start(Context context, DownloadListener listener,boolean isOnlyGetHead) {
//Get context,which will be used to communicate with sqlite.
if (this.context == null && context != null) {
this.context = context;
}
if (task != null) {
task.cancel(false);
}
task = new AsycDownloadTask(listener,isOnlyGetHead);
task.execute(this);
}
/**
* Stop the task
*/
protected void stop(){
setStatus(DownloadStatus.STATUS_STOPPED);
if (task != null) {
task.cancel(false);
}
}
/**
* Delete the task
*/
protected void delete(){
setStatus(DownloadStatus.STATUS_DELETED);
if (task != null) {
task.cancel(false);
}
}
}
but get errors as follows:
E/AndroidRuntime(30057): Caused by: java.lang.IllegalArgumentException: No fields have a DatabaseField annotation in class com.github.snowdream.android.a.a.j
E/AndroidRuntime(30057): at com.j256.ormlite.table.DatabaseTableConfig.void extractFieldTypes(com.j256.ormlite.support.ConnectionSource)(Unknown Source)
com.j256.ormlite.field.FieldType[] extractFieldTypes(com.j256.ormlite.support.ConnectionSource,java.lang.Class,java.lang.String)
E/AndroidRuntime(30057): at com.j256.ormlite.table.DatabaseTableConfig.com.j256.ormlite.table.DatabaseTableConfig fromClass(com.j256.ormlite.support.ConnectionSource,java.lang.Class)(Unknown Source)
E/AndroidRuntime(30057): at com.j256.ormlite.table.TableInfo.<init>(Unknown Source)
E/AndroidRuntime(30057): at com.j256.ormlite.dao.BaseDaoImpl.void initialize()(Unknown Source)
E/AndroidRuntime(30057): at com.j256.ormlite.dao.BaseDaoImpl.<init>(Unknown Source)
E/AndroidRuntime(30057): at com.j256.ormlite.dao.BaseDaoImpl.<init>(Unknown Source)
E/AndroidRuntime(30057): at com.j256.ormlite.dao.BaseDaoImpl$4.<init>(Unknown Source)
E/AndroidRuntime(30057): at com.j256.ormlite.dao.BaseDaoImpl.com.j256.ormlite.dao.Dao createDao(com.j256.ormlite.support.ConnectionSource,java.lang.Class)(Unknown Source)
com.j256.ormlite.dao.Dao createDao(com.j256.ormlite.support.ConnectionSource,com.j256.ormlite.table.DatabaseTableConfig)
E/AndroidRuntime(30057): at com.j256.ormlite.dao.DaoManager.com.j256.ormlite.dao.Dao createDao(com.j256.ormlite.support.ConnectionSource,java.lang.Class)(Unknown Source)
com.j256.ormlite.dao.Dao createDao(com.j256.ormlite.support.ConnectionSource,com.j256.ormlite.table.DatabaseTableConfig)
E/AndroidRuntime(30057): at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.com.j256.ormlite.dao.Dao getDao(java.lang.Class)(Unknown Source)
E/AndroidRuntime(30057): at com.github.snowdream.android.app.downloader.dao.DatabaseHelper.com.github.snowdream.android.app.downloader.dao.DatabaseHelper getHelper(android.content.Context)(Unknown Source)
com.j256.ormlite.dao.Dao getTaskDao()
E/AndroidRuntime(30057): at com.github.snowdream.android.app.downloader.dao.ISqlImpl.com.github.snowdream.android.app.downloader.DownloadTask queryDownloadTask(com.github.snowdream.android.app.downloader.DownloadTask)(Unknown Source)
E/AndroidRuntime(30057): at com.github.snowdream.android.app.downloader.DownloadManager.void a(com.github.snowdream.android.app.downloader.DownloadManager$a,com.github.snowdream.android.app.downloader.DownloadTask,com.github.snowdream.android.app.downloader.DownloadListener,java.lang.Integer)(Unknown Source)
void add(com.github.snowdream.android.app.downloader.DownloadTask,com.github.snowdream.android.app.downloader.DownloadListener)
E/AndroidRuntime(30057): at com.github.snowdream.android.apps.downloader.MainActivity.void onCreate(android.os.Bundle)(Unknown Source)
E/AndroidRuntime(30057): at android.app.Activity.performCreate(Activity.java:5990)
E/AndroidRuntime(30057): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
E/AndroidRuntime(30057): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
E/AndroidRuntime(30057): ... 10 more
W/ActivityManager( 784): Force finishing activity 1 com.github.snowdream.android.apps.downloader/.MainActivity
Upvotes: 0
Views: 2703
Reputation: 2126
My answer from here:
It's probably late for giving solution but this is my solution:
you see proguard try to obfuscating the code and if you read proguard in depth or intro
http://proguard.sourceforge.net/FAQ.html
What Shrinking in proguard Shrinking programs such as ProGuard can analyze bytecode and remove unused classes, fields, and methods. so from this we can presume that it is removing your objects since it's not used by anywhere...
so What you need probably? you need to stop proguard from shirking that methods or objects from process.
Check below line for that
-keep class com.j256.**<br>
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
This line will keep pro guard from removing my public methods and variables.
-keepclassmembers class classpath.** {
public *;
}
You need to write column name for atlest id... because it will search for it and will proguard change it's name... so you need to define column name id for primary key..
Upvotes: 2