简体   繁体   English

java.lang.ClassCastException:org.apache.camel.builder.ValueBuilder无法转换为java.lang.String

[英]java.lang.ClassCastException: org.apache.camel.builder.ValueBuilder cannot be cast to java.lang.String

I am getting crazy because I am not able to track down why I have this exception in my camel route: 我发疯了,因为我无法追踪为什么我的骆驼路线中有这个例外:

java.lang.ClassCastException: org.apache.camel.builder.ValueBuilder
cannot be  cast to java.lang.String

Can you please give me an hint of what does it mean? 您能给我提示一下这是什么意思吗? I have no explicit casts in my code. 我的代码中没有明确的强制转换。

After seeing your (correct) annotations I add: 在看到您的(正确)注释后,我添加:

  1. I cannot reproduce the exception in a few lines of code because in this case I was able to solve it on my own 我无法在几行代码中重现异常,因为在这种情况下,我能够自行解决它
  2. I know what a classcast exception is but infact I never assign a valuebuilder to a string variable or cast a string 我知道什么是类广播异常,但实际上我从未将valuebuilder分配给字符串变量或强制转换了字符串
  3. I tried to debug and trace but the same piece of code that now works tomorrow launches this exception 我尝试调试和跟踪,但是明天可用的同一段代码会引发此异常
  4. I have read camel documentation but probably I still do not understand what a ValueBuilder is for 我已经阅读过骆驼文档,但可能我仍然不明白ValueBuilder的用途

Can you suggest me a better way to debug exceptions with eclipse debugger? 您能建议我用Eclipse调试器调试异常的更好方法吗?

I can finally add the exception WITH stacktrace: 我终于可以使用stacktrace添加异常:

java.lang.ClassCastException
org.apache.camel.builder.ValueBuilder cannot be cast to java.lang.String
at org.apache.camel.component.cache.CacheProducer.process(CacheProducer.java:61)       
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.  process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122)
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor. processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.management.InstrumentationProcessor. process(InstrumentationProcessor.java:72)

Thanks, Mario 谢谢,马里奥

From the API Specifications for the ClassCastException : ClassCastException的API规范中:

Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. 抛出该异常以指示代码已尝试将对象强制转换为不是实例的子类。

So, for example, when you try to assign a org.apache.camel.builder.ValueBuilder to a java.lang.String , the operation fails to be accomplished because java.lang.String is not an subclass of org.apache.camel.builder.ValueBuilder , and therefore a ClassCastException is thrown. 因此,例如,当您尝试将org.apache.camel.builder.ValueBuilder分配给java.lang.String ,操作将无法完成,因为java.lang.String不是org.apache.camel.builder.ValueBuilder的子类。 org.apache.camel.builder.ValueBuilder ,因此ClassCastException

I have found the problem! 我发现了问题!

This is the previous code (that worked), taken from official camel tutorial: 这是先前的代码(有效),摘自官方骆驼教程:

in.setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD));

This is the correct code that produces no exception: 这是不产生异常的正确代码:

in.setHeader(CacheConstants.CACHE_OPERATION, CacheConstants.CACHE_OPERATION_ADD);

constant() changes a String in a ValueBuilder causing the exception. constant()更改导致异常的ValueBuilder中的String。

I suppose this is a bug because the behaviour of camel cache component has changed. 我认为这是一个错误,因为骆驼缓存组件的行为已更改。

Mario 马里奥

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.ClassCastException:java.lang.String 无法转换为 org.apache.avro.generic.GenericRed - java.lang.ClassCastException: java.lang.String cannot be cast to org.apache.avro.generic.GenericRecord java.lang.ClassCastException:无法将java.lang.String强制转换为org.myapp.ui.MyClass - java.lang.ClassCastException: java.lang.String cannot be cast to org.myapp.ui.MyClass java.lang.ClassCastException: java.lang.String 不能转换为 org.json.JSONObject - java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject JasperReports:java.lang.ClassCastException:无法将java.lang.String强制转换为java.lang.Character - JasperReports:java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Character JasperReports:取得java.lang.ClassCastException:java.lang.String无法转换为java.lang.Number - JasperReports: getting java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number java.lang.ClassCastException:java.lang.Double无法强制转换为java.lang.String - java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String java.lang.ClassCastException:无法在Tableau中将java.lang.String强制转换为java.lang.Integer? - java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer in tableau? java.lang.ClassCastException : java.lang.String 不能转换为 java.lang.Long - java.lang.ClassCastException : java.lang.String cannot be cast to java.lang.Long java.lang.ClassCastException:java.lang.String无法强制转换为java.lang.Long - java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long JRException:java.lang.ClassCastException:java.lang.String无法转换为java.lang.Boolean - JRException: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM