以下是我在Kotlin中尝试过的简单图表视图代码。但它不能正常工作。应用程序在运行时崩溃。
`lateinit var series: LineGraphSeries<DataPoint>
var x : Double = 0.0; var y : Double = 0.0`
的OnCreate
var graphview : GraphView = findViewById(R.id.graphview) as GraphView
series = LineGraphSeries<DataPoint>()
x = -0.5
for (i in 0..500)
{
x += 0.1
y = Math.sinh(x)
series.appendData(DataPoint(x,y), true, 500)
}
graphview.addSeries(series)
错误记录
FATAL EXCEPTION: main
Process: com.example.sarath.mykotinapplication, PID: 18986
java.lang.OutOfMemoryError: Failed to allocate a 1073741836 byte allocation with 13311040 free bytes and 172MB until OOM
at java.util.HashMap.inflateTable(HashMap.java:287)
at java.util.HashMap.put(HashMap.java:419)
at com.jjoe64.graphview.GridLabelRenderer.adjustVertical(GridLabelRenderer.java:791)
at com.jjoe64.graphview.GridLabelRenderer.adjustSteps(GridLabelRenderer.java:932)
at com.jjoe64.graphview.GridLabelRenderer.draw(GridLabelRenderer.java:1067)
at com.jjoe64.graphview.GraphView.drawGraphElements(GraphView.java:299)
at com.jjoe64.graphview.GridLabelRenderer.draw(GridLabelRenderer.java:1062)
at com.jjoe64.graphview.GraphView.drawGraphElements(GraphView.java:299)
at com.jjoe64.graphview.GraphView.onDraw(GraphView.java:323)
at android.view.View.draw(View.java:17077)
at android.view.View.updateDisplayListIfDirty(View.java:16059)
at android.view.View.draw(View.java:16843)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16054)
at android.view.View.draw(View.java:16843)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16054)
at android.view.View.draw(View.java:16843)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16054)
at android.view.View.draw(View.java:16843)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16054)
at android.view.View.draw(View.java:16843)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16054)
at android.view.View.draw(View.java:16843)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.draw(View.java:17080)
at com.android.internal.policy.DecorView.draw(DecorView.java:751)
at android.view.View.updateDisplayListIfDirty(View.java:16059)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:656)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:662)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:770)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2841)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2649)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2256)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1291)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6357)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:873)
at android.view.Choreographer.doCallbacks(Choreographer.java:685)
at android.view.Choreographer.doFrame(Choreographer.java:621)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6195)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
08-21 10:56:32.022 18986-18986 / com.example.sarath.mykotinapplication E / MQSEventManagerDelegate:无法获得MQSService。
是否有任何代码错误?它是研究的一部分,期待来自专家的关于kotlin的建议
答案 0 :(得分:0)
Math.sinh(x)方法就是问题所在。我为罪(x),法术错误做好了准备。上面的代码工作正常,y值略有变化。将y = Math.sinh(x)更改为 y = Math.sin(x)。这里我使用的是Graphview库here。希望这会对某人有所帮助。 感谢