Java math bigdecimal cannot be cast to java math bigdecimal

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ClassCastException: class java.math.BigDecimal cannot be cast to class java.lang.Integer #26

java.lang.ClassCastException: class java.math.BigDecimal cannot be cast to class java.lang.Integer #26

Comments

I’m still working on some tests with this driver, and whenever I need to read a numeric value from result set and cast it to Int like below:

return r2dbcTemplate .databaseClient .sql("select count(1) as total_orders from orders") .fetch() .one() .flatMap < row -> Mono.just(row["total_orders"] as Int) >
java.lang.ClassCastException: class java.math.BigDecimal cannot be cast to class java.lang.Integer (java.math.BigDecimal and java.lang.Integer are in module java.base of loader 'bootstrap') ... at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:125) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:82) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxFlatMap$FlatMapMain.tryEmitScalar(FluxFlatMap.java:488) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:421) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxBuffer$BufferExactSubscriber.onComplete(FluxBuffer.java:185) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onComplete(Operators.java:2057) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxUsingWhen$UsingWhenSubscriber.deferredComplete(FluxUsingWhen.java:405) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxUsingWhen$CommitInner.onComplete(FluxUsingWhen.java:540) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onComplete(Operators.java:2057) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:259) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onComplete(Operators.java:2057) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.Operators$MonoSubscriber.onComplete(Operators.java:1857) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoIgnoreThen$ThenAcceptInner.onComplete(MonoIgnoreThen.java:323) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.Operators$MonoSubscriber.onComplete(Operators.java:1857) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoIgnoreThen$ThenAcceptInner.onComplete(MonoIgnoreThen.java:323) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.pool.SimpleDequePool$QueuePoolRecyclerInner.onComplete(SimpleDequePool.java:678) ~[reactor-pool-0.2.3.jar!/:0.2.3] at reactor.core.publisher.Operators.complete(Operators.java:136) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoEmpty.subscribe(MonoEmpty.java:45) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.Mono.subscribe(Mono.java:4099) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.pool.SimpleDequePool$QueuePoolRecyclerMono.subscribe(SimpleDequePool.java:790) ~[reactor-pool-0.2.3.jar!/:0.2.3] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:154) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:154) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.Mono.subscribe(Mono.java:4099) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:103) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoIgnoreElements$IgnoreElementsSubscriber.onError(MonoIgnoreElements.java:83) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxMap$MapSubscriber.onError(FluxMap.java:132) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxFilter$FilterSubscriber.onError(FluxFilter.java:157) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxFilter$FilterConditionalSubscriber.onError(FluxFilter.java:291) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onError(FluxMap.java:259) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.Operators.error(Operators.java:197) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoError.subscribe(MonoError.java:52) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoDeferContextual.subscribe(MonoDeferContextual.java:55) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.Mono.subscribe(Mono.java:4099) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxUsingWhen$UsingWhenSubscriber.onComplete(FluxUsingWhen.java:397) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxFlatMap$FlatMapMain.checkTerminated(FluxFlatMap.java:846) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxFlatMap$FlatMapMain.drainLoop(FluxFlatMap.java:608) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxFlatMap$FlatMapMain.innerComplete(FluxFlatMap.java:894) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.FluxFlatMap$FlatMapInner.onComplete(FluxFlatMap.java:997) ~[reactor-core-3.4.4.jar!/:3.4.4] at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onComplete(Operators.java:2057) ~[reactor-core-3.4.4.jar!/:3.4.4] at org.reactivestreams.FlowAdapters$FlowToReactiveSubscriber.onComplete(FlowAdapters.java:228) ~[reactive-streams-1.0.3.jar!/:na] at oracle.jdbc.driver.PhasedPublisher$PhasedSubscription.emitComplete(PhasedPublisher.java:434) ~[ojdbc11-21.1.0.0.jar!/:21.1.0.0.0] at oracle.jdbc.driver.PhasedPublisher.lambda$subscribe$3(PhasedPublisher.java:343) ~[ojdbc11-21.1.0.0.jar!/:21.1.0.0.0] at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859) ~[na:na] at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837) ~[na:na] at java.base/java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:478) ~[na:na] at oracle.jdbc.driver.PhysicalConnection.lambda$createUserCodeExecutor$10(PhysicalConnection.java:11713) ~[ojdbc11-21.1.0.0.jar!/:21.1.0.0.0] at java.base/java.security.AccessController.doPrivileged(AccessController.java:391) ~[na:na] at oracle.jdbc.driver.PhysicalConnection.lambda$createUserCodeExecutor$11(PhysicalConnection.java:11711) ~[ojdbc11-21.1.0.0.jar!/:21.1.0.0.0] at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1429) ~[na:na] at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) ~[na:na] at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016) ~[na:na] at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665) ~[na:na] at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598) ~[na:na] at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183) ~[na:na]

Off course, it is possible to use BigDecimal for any numeric value (and then converting it to Int/Long, etc), but I don’t know if this is some compatibility error between spring/ojdbc11/oracle-r2dbc, or something expected at this moment.

Читайте также:  Php abstract class implements interface

Are other numeric types (besides BigDecimal) supported already?

The text was updated successfully, but these errors were encountered:

Источник

Как исправить java.lang.ClassCastException: java.lang.Double нельзя привести к ошибке java.math.BigDecimal для выражения переменной?

У меня есть переменная, которая возвращает ошибку при включении в отчет (предварительный просмотр), но при компиляции ошибки нет.

Предполагается, что переменная выводит в отчете двузначное число в зависимости от количества поля.

У меня есть поле $F типа java.lang.String и переменная $V , которая преобразует его в число. Переменная $V имеет тип java.math.BigDecimal :

Основная часть состоит в том, чтобы напечатать в отчете другое двузначное число в зависимости от количества $V . Эта переменная называется $V типа java.lang.String :

 .doubleValue() .doubleValue() .doubleValue() .doubleValue() 

Я должен начать с общего баланса поля, который имеет строковый тип. При компиляции ошибки нет. Но если я создаю поле для вывода переменной, а затем нажимаю на предварительный просмотр, я получаю эту ошибку:

net.sf.jasperreports.engine.fill.jrexpressionevalexception error evaluating expression net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression: Source text: $V.doubleValue() <= new java.math.BigDecimal(250).doubleValue() ? "15":($V.doubleValue() <= new java.math.BigDecimal(1000).doubleValue() ? "30" ($V.doubleValue() <= new java.math.BigDecimal(10000).doubleValue() ? "30" : ($V.doubleValue() <= new java.math.BigDecimal(50000).doubleValue() ? "40":"0" ) ) ) at com.jaspersoft.studio.editor.preview.view.control.ReportControler.fillReport(ReportControler.java:466) .. Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : $V.doubleValue() <= new java.math.BigDecimal(250).doubleValue() ? "15":($V.doubleValue() <= new java.math.BigDecimal(1000).doubleValue() ? "30": ($V.doubleValue() <= new java.math.BigDecimal(10000).doubleValue() ? "30" ($V.doubleValue()  

Пример кода для повторения проблемы:

       ))]]>  .doubleValue() .doubleValue() .doubleValue() .doubleValue()   ]]>       

А также код xml для использования в качестве адаптера для входных данных (сохраните его как xml -> создайте новый адаптер данных в студии Jaspersoft -> выберите документ XML -> выберите файл и выберите использовать выражение Xpath отчета при заполнении отчета -> финиш)

Спасибо за напоминание. Я добавил пример кода для воспроизведения проблемы в свой исходный пост.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ClassCastException: scala.math.BigDecimal cannot be cast to java.math.BigDecimal #54

java.lang.ClassCastException: scala.math.BigDecimal cannot be cast to java.math.BigDecimal #54

Comments

Hi, I get cast error when I tried this code:
BigDecimal test = row.get(0);
(mysql field type is "decimal")

error:
java.lang.ClassCastException: scala.math.BigDecimal cannot be cast to java.math.BigDecimal

I am using:
io.vertx lang-scala_2.11 1.1.0-M1
io.vertx mod-mysql-postgresql_2.11 0.3.1

The text was updated successfully, but these errors were encountered:

Actually, I'm not sure how it transports decimals anyway. I'll need to have a look, but as it's just JSON, it shouldn't actually have any BigDecimal classes in there at all?

Could you provide a small test maybe?

Yes there is. I will try with the other version later today thanks

On Wednesday, October 29, 2014, Joern Bernhardt notifications@github.com
wrote:

Actually, I'm not sure how it transports decimals anyway. I'll need to
have a look, but as it's just JSON, it shouldn't actually have any
BigDecimal classes in there at all?


Reply to this email directly or view it on GitHub
#54 (comment)
.

Hi, I found another way to solve this by adding scala library to my project, and converting the type myself from scala type to java type, and it worked!

You can’t perform that action at this time.

Источник

Оцените статью