我正在使用离子库从服务器获取数据并将数据存储在Ralm中。
final Context context = view.getContext();
Ion.with(context)
.load(TeamConstants.TEAM_URL + "team-masters")
.asJsonArray()
.setCallback(new FutureCallback<JsonArray>() {
public void onCompleted(Exception e, JsonArray result) {
//TODO update realm data for updateTeam
Toast.makeText(context, " success !!", Toast.LENGTH_SHORT).show();
try {
if (e == null) {
gameRealm =
Realm.getInstance(
new RealmConfiguration.Builder(context)
.name("AllTeams.realm")
.deleteRealmIfMigrationNeeded()
.build()
);
gameRealm.beginTransaction();
for (int i = 0; i < result.size(); i++) {
AllTeamData coachTeamsData = new AllTeamData();
coachTeamsData.setTeamId(result.get(i).getAsJsonObject().get("id").getAsInt());
coachTeamsData.setTeamLocation(result.get(i).getAsJsonObject().get("location").getAsString());
coachTeamsData.setTeamName(result.get(i).getAsJsonObject().get("name").getAsString());
coachTeamsData.setCoachId(result.get(i).getAsJsonObject().get("coach_id").getAsInt());
}
}
} catch (Exception ex) {
Util.Log("Exception",ex.getMessage());
}
}
});
resultTeamNames = gameRealm.where(CoachTeamsData.class).findAll();
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: java.lang.NullPointerException
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at org.openinfotech.teammanagement.teams.AllTeamsFragment.onCreateView(AllTeamsFragment.java:97)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:164)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.view.ViewPager.populate(ViewPager.java:1025)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1545)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1075)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2421)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.View.measure(View.java:16677)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1927)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1119)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1301)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1006)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5652)
06-22 12:11:17.171 17770-17770/org.openinfotech.teammanagement E/AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)