Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GenericClass doesn't support Class<float>

I am integrating scichart to my android project and facing this error. I need to display ohlc data so, base on this tutorial https://www.scichart.com/example/android-candlestick-chart-example/ I wrote

val dataSeries = OhlcDataSeries(Date::class.java, Double::class.java)

That was translated from java code

IOhlcDataSeries<Date, Double> dataSeries = new OhlcDataSeries<>(Date.class, Double.class);

I got this error

E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.qh.cointracker, PID: 5275
  java.util.NoSuchElementException: GenericClass doesn't support Class<double>
   at com.scichart.data.numerics.math.GenericMathFactory.create(GenericMathFactory.java:65)
   at com.scichart.charting.model.dataSeries.DataSeries.<init>(DataSeries.java:91)
   at com.scichart.charting.model.dataSeries.XDataSeries.<init>(XDataSeries.java:58)
   at com.scichart.charting.model.dataSeries.OhlcDataSeries.<init>(OhlcDataSeries.java:58)
   at com.scichart.charting.model.dataSeries.OhlcDataSeries.<init>(OhlcDataSeries.java:73)
   at com.qh.cointracker.activities.fragments.SymbolChartFragment.initExample(SymbolChartFragment.kt:57)
   at com.qh.cointracker.activities.fragments.SymbolChartFragment.onViewCreated(SymbolChartFragment.kt:37)

Can someone give me any idea to solve this error

Thank you.

like image 594
Võ Quang Hòa Avatar asked Feb 26 '18 04:02

Võ Quang Hòa


2 Answers

The problem is that your code is working with the corresponding primitive type. You can use the following property defined on KClass instead:

/**
 * Returns a Java [Class] instance corresponding to the given [KClass] instance.
 * In case of primitive types it returns corresponding wrapper classes.
 */
public val <T : Any> KClass<T>.javaObjectType: Class<T>

As the KDoc describes, the corresponding wrapper type will be returned:

Double::class.javaObjectType //class java.lang.Double
like image 81
s1m0nw1 Avatar answered Nov 17 '22 01:11

s1m0nw1


I know its already answered, but for future reference:

There are examples of using SciChart Android Charts with Kotlin on their public github page. Under the v2.x -> Showcase folder

The EcgViewModel.kt shows how to create and fill XyDataSeries

The StockChartViewModel.kt shows how to create and fill OhlcDataSeries

like image 3
Dr. Andrew Burnett-Thompson Avatar answered Nov 17 '22 00:11

Dr. Andrew Burnett-Thompson