当前位置: 代码迷 >> Android >> 遇到个空指针异常,没有指出异常在哪,求指教。用jxl.jar生成一个GraphicalView,addView()到一个LinearLayout里产生的
  详细解决方案

遇到个空指针异常,没有指出异常在哪,求指教。用jxl.jar生成一个GraphicalView,addView()到一个LinearLayout里产生的

热度:28   发布时间:2016-05-01 21:10:23.0
遇到个空指针错误,没有指出错误在哪,求指教。用jxl.jar生成一个GraphicalView,addView()到一个LinearLayout里产生的
java.lang.NullPointerException
  at android.graphics.Canvas.throwIfRecycled(Canvas.java:954)
  at android.graphics.Canvas.drawBitmap(Canvas.java:980)
  at org.achartengine.GraphicalView.onDraw(GraphicalView.java:174)
  at android.view.View.draw(View.java:6880)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
  at android.view.View.draw(View.java:6883)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
  at android.view.View.draw(View.java:6883)
  at android.widget.FrameLayout.draw(FrameLayout.java:357)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
  at android.view.View.draw(View.java:6883)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
  at android.view.View.draw(View.java:6883)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
  at android.view.View.draw(View.java:6883)
  at android.widget.FrameLayout.draw(FrameLayout.java:357)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
  at android.view.View.draw(View.java:6883)
  at android.widget.FrameLayout.draw(FrameLayout.java:357)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1862)
  at android.view.ViewRoot.draw(ViewRoot.java:1522)
  at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
  at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:3683)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:507)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  at dalvik.system.NativeStart.main(Native Method)


------解决方案--------------------
这不就是出错位置吗?第174行
at org.achartengine.GraphicalView.onDraw(GraphicalView.java:174)
 
------解决方案--------------------
你通过LinearLayout chartView; 只定义了chartView这个对象类型,但是未看到有实始对像的代码,也就是说chartView是null,你要在onCreate里面再增加一个代码:
chartView = new LinearLayout(getApplicationContext());
  相关解决方案