您好我正在使用sq lite数据库,以便绘制一个图形图表视图库,我在git hub中创建但是在推出应用程序时我强行关闭! 我从数据库中获取数据作为列表,然后我想从我的数据库获取x和y图。
这是我的代码:
public class lagari_graph extends SherlockFragment {
List<calery_lagari> Calery_lagari;
calery_lagari_SQLiteData data;
calery_lagari Calery_lagaris;
int i;
GraphView graphView;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.lagari_graph, null);
return v;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
int size = Calery_lagari.size();
GraphViewData[] data = new GraphViewData[size];
for (i=0; i<size; i++) {
Calery_lagaris = Calery_lagari.get(i);
data[i] = new GraphViewData(i, Calery_lagaris.getcalery());
}
GraphViewSeries Series = new GraphViewSeries(data);
graphView = new LineGraphView(
getActivity()
, "graph" );
graphView.addSeries(Series);
LinearLayout layout = (LinearLayout) view.findViewById(R.id.lin);
layout.addView(graphView);
super.onViewCreated(view, savedInstanceState);
}
}
日志:
12-14 19:09:51.242: E/AndroidRuntime(2259): FATAL EXCEPTION: main
12-14 19:09:51.242: E/AndroidRuntime(2259): java.lang.NullPointerException
12-14 19:09:51.242: E/AndroidRuntime(2259): at mr.chag.va.lagar.lagari.lagari_graph.onViewCreated(lagari_graph.java:34)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:431)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:160)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.support.v4.view.ViewPager.populate(ViewPager.java:804)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.support.v4.view.ViewPager.completeScroll(ViewPager.java:1280)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.support.v4.view.ViewPager.computeScroll(ViewPager.java:1176)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.getDisplayList(View.java:12397)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.getDisplayList(View.java:12453)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.draw(View.java:13182)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.getDisplayList(View.java:12407)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.getDisplayList(View.java:12453)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2911)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.getDisplayList(View.java:12345)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.getDisplayList(View.java:12453)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2911)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.getDisplayList(View.java:12345)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.getDisplayList(View.java:12453)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2911)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.getDisplayList(View.java:12345)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.View.getDisplayList(View.java:12453)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1144)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2147)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2019)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1830)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.Choreographer.doFrame(Choreographer.java:525)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.os.Handler.handleCallback(Handler.java:615)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.os.Handler.dispatchMessage(Handler.java:92)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.os.Looper.loop(Looper.java:137)
12-14 19:09:51.242: E/AndroidRuntime(2259): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-14 19:09:51.242: E/AndroidRuntime(2259): at java.lang.reflect.Method.invokeNative(Native Method)
12-14 19:09:51.242: E/AndroidRuntime(2259): at java.lang.reflect.Method.invoke(Method.java:511)
12-14 19:09:51.242: E/AndroidRuntime(2259): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-14 19:09:51.242: E/AndroidRuntime(2259): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-14 19:09:51.242: E/AndroidRuntime(2259): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
问题是您没有定义我的意思calery_lagari_SQLiteData data;
尝试在您的片段中定义数据
data = ......