我有两个表User
和Roles
,一对一的关系如下所示。
User
_________________________________________
| Id | user_name | full_name | creator |
_________________________________________
| 1 | a | A | a |
| 2 | b | B | a |
| 3 | c | C | a |
| 4 | d | D | c |
| 5 | e | E | c |
| 6 | f | F | e |
| 7 | g | G | e |
| 8 | h | H | e |
| 9 | i | I | e |
|10 | j | J | i |
_________________________________________
Roles
_______________________________________
| id | user_mgmt | others | user_id |
_______________________________________
| 1 | 1 | 1 | 1 |
| 2 | 0 | 1 | 2 |
| 3 | 1 | 0 | 3 |
| 4 | 0 | 1 | 4 |
| 5 | 1 | 1 | 5 |
| 6 | 0 | 1 | 6 |
| 7 | 0 | 0 | 7 |
| 8 | 0 | 0 | 8 |
| 9 | 1 | 0 | 9 |
________________________________________
Roles
表格有boolean
个列,因此如果User
具有user_mgmt
个角色,则可以添加多个用户(用户可以添加多少个用户)定)。我想获取用户和他的子用户创建的所有用户(a是父级,c是a的子级,e是c的子级)。
以下是我获取用户的代码
public void loadUsers(){
List<Users> users = new ArrayList<>();
String creator = user.getUserName();
List<Users> createdUsers = userService.getUsersByCreator(creator);
for(Users user : createdUsers) {
Roles role = createdUsers.getRoles();
if(role.isEmpMgnt()){
users.add(user);
loadUsers();
}
}
}
这给了我一个堆栈溢出错误。如果我不以递归方式调用loadUsers()
,则只返回单个子结果。那有什么解决方案吗?感谢您提前提供任何帮助。
答案 0 :(得分:1)
这会导致堆栈溢出错误,因为12-02 00:32:50.429 3720-4954/? E/Parcel: Class not found when unmarshalling: com.facebook.gdp.LightWeightLoginParameters
java.lang.ClassNotFoundException: com.facebook.gdp.LightWeightLoginParameters
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:400)
at android.os.Parcel.readParcelableCreator(Parcel.java:2517)
at android.os.Parcel.readParcelable(Parcel.java:2471)
at android.os.Parcel.readValue(Parcel.java:2374)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2727)
at android.os.BaseBundle.unparcel(BaseBundle.java:269)
at android.os.BaseBundle.getString(BaseBundle.java:992)
at android.content.Intent.getStringExtra(Intent.java:6702)
at com.android.server.am.ActivityStarter.startActivityLocked(ActivityStarter.java:336)
at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:1094)
at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:5822)
at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:5627)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:176)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3612)
at android.os.Binder.execTransact(Binder.java:573)
Caused by: java.lang.ClassNotFoundException: com.facebook.gdp.LightWeightLoginParameters
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:1346)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:1406)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:400)
at android.os.Parcel.readParcelableCreator(Parcel.java:2517)
at android.os.Parcel.readParcelable(Parcel.java:2471)
at android.os.Parcel.readValue(Parcel.java:2374)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2727)
at android.os.BaseBundle.unparcel(BaseBundle.java:269)
at android.os.BaseBundle.getString(BaseBundle.java:992)
at android.content.Intent.getStringExtra(Intent.java:6702)
at com.android.server.am.ActivityStarter.startActivityLocked(ActivityStarter.java:336)
at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:1094)
at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:5822)
at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:5627)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:176)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3612)
at android.os.Binder.execTransact(Binder.java:573)
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
12-02 00:32:50.429 3720-4954/? W/Bundle: Failed to parse Bundle, but defusing quietly
android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.facebook.gdp.LightWeightLoginParameters
at android.os.Parcel.readParcelableCreator(Parcel.java:2545)
at android.os.Parcel.readParcelable(Parcel.java:2471)
at android.os.Parcel.readValue(Parcel.java:2374)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2727)
at android.os.BaseBundle.unparcel(BaseBundle.java:269)
at android.os.BaseBundle.getString(BaseBundle.java:992)
at android.content.Intent.getStringExtra(Intent.java:6702)
at com.android.server.am.ActivityStarter.startActivityLocked(ActivityStarter.java:336)
at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:1094)
at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:5822)
at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:5627)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:176)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3612)
at android.os.Binder.execTransact(Binder.java:573)
有创建者a
。所以你有一个无限循环的用户a。对于a
,您应将创建者设置为a
或跳过代码中的自引用。
此外,您应该将当前用户传递给null
方法,并且只读取由其创建的用户。喜欢
loadUsers()
并且仅处理由该创建者创建的用户。在这里
public void loadUsers(String creator)
什么是用户?你应该使用创作者。问题是你如何获得初始创作者。可能初始创建者应该是创建者为空的用户。