gpt4 book ai didi

android - ORMLite 错误 : No fields have a DatabaseField annotation in class java. lang.Character

转载 作者:搜寻专家 更新时间:2023-11-01 08:56:22 25 4
gpt4 key购买 nike

我使用 4.46 版本的核心 ORMLite 和 Android,我一直有这个问题。

Foo 类

@DatabaseTable
public class Foo {

@DatabaseField(generatedId = true)
public int id;
@DatabaseField(index = true)
public String title;
@ForeignCollectionField
ForeignCollection<Foo2> foo2s;

public Foo() {
// needed by ormlite
}

}

Foo2 类

@DatabaseTable
public class Foo2 {

@DatabaseField(generatedId = true)
public int id;
@DatabaseField
public Date date;

public Foo2() {
// needed by ormlite
}
}

ORMLiteFragment(我需要从 Fragment 调用 getHelper())

public class OrmLiteFragment extends Fragment {

private DatabaseHelper databaseHelper = null;

protected DatabaseHelper getHelper() {
if (databaseHelper == null) {
databaseHelper =
OpenHelperManager.getHelper(getActivity(), DatabaseHelper.class);
}
return databaseHelper;
}

@Override
public void onDestroy() {
super.onDestroy();
if (databaseHelper != null) {
OpenHelperManager.releaseHelper();
databaseHelper = null;
}
}
}

Activity

public class MainActivity extends FragmentActivity {
/**
* Some methods non important for this...
*/

public static class SectionFragment extends OrmLiteFragment {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {

// Some code....

getHelper().getFoo2RuntimeDao(); // HERE FIRES THE ERROR!

// Some code....
}
}
}

DatabaseHelper 类与Android examples code page 相同但是使用 Foo2RuntimeDao() 和 Foo1RuntimeDao()

问题

09-03 14:27:15.756: E/AndroidRuntime(557): FATAL EXCEPTION: main
09-03 14:27:15.756: E/AndroidRuntime(557): java.lang.IllegalArgumentException: No fields have a DatabaseField annotation in class java.lang.Character
09-03 14:27:15.756: E/AndroidRuntime(557): at com.j256.ormlite.table.DatabaseTableConfig.extractFieldTypes(DatabaseTableConfig.java:215)
09-03 14:27:15.756: E/AndroidRuntime(557): at com.j256.ormlite.table.DatabaseTableConfig.fromClass(DatabaseTableConfig.java:146)
09-03 14:27:15.756: E/AndroidRuntime(557): at com.j256.ormlite.table.TableInfo.<init>(TableInfo.java:53)
09-03 14:27:15.756: E/AndroidRuntime(557): at com.j256.ormlite.dao.BaseDaoImpl.initialize(BaseDaoImpl.java:149)
09-03 14:27:15.756: E/AndroidRuntime(557): at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:126)

- 更新 1

如果我尝试得到 queryForAll() (返回一个列表)并且我之前没有保存数据我得到一个 NullPointerException 而不是一个空列表或 null。像这样:

public class MainActivity2 extends OrmLiteBaseActivity<DatabaseHelper> {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getHelper().getChapterRunDao(); //This Works!
getHelper().getChapterRunDao().queryForAll(); //This throws NullPointerException
}
}

问题

09-04 15:32:13.261: E/AndroidRuntime(3615): FATAL EXCEPTION: main
09-04 15:32:13.261: E/AndroidRuntime(3615): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emanga/com.emanga.ORMLite}: java.lang.NullPointerException
09-04 15:32:13.261: E/AndroidRuntime(3615): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
09-04 15:32:13.261: E/AndroidRuntime(3615): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)

最佳答案

如果您没有字段错误,这将有所帮助
我在这里的回答:ORMLite error no databasefield annotations exists
给出解决方案可能已经晚了,但这是我的解决方案:
你看到混淆器试图混淆代码,如果你深入阅读混淆器或介绍

http://proguard.sourceforge.net/FAQ.html

what Shrinking in proguard -> ProGuard之类的Shrinking程序可以分析字节码,移除不用的类、字段和方法。所以从这里我们可以假设它正在删除你的对象,因为它没有被任何地方使用......
所以你可能需要?您需要阻止混淆器从进程中逃避该方法或对象所以这是该行..:
-keep class com.j256.**<br>
-keepclassmembers class com.j256.** { *; }<br>
-keep enum com.j256.**<br>
-keepclassmembers enum com.j256.** { *; }<br>
-keep interface com.j256.**<br>
-keepclassmembers interface com.j256.** { *; }


这一行将阻止混淆器删除我的公共(public)方法和变量..

-keepclassmembers class classpath.** {
public *;
}

你需要为atlest id写列名...因为它会搜索它并且proguard会改变它的名字...所以你需要为主键定义列名id..

关于android - ORMLite 错误 : No fields have a DatabaseField annotation in class java. lang.Character,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18594726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com