很明顯是類型轉換錯誤。即Integer 類型不能轉成String類型。?
解決方案:
1.直接使用tosting的方式?
String str = entry.value().toString();?
2.使用String類的靜態方法valueOf()
String str = String.valueOf(entry.value());3. String orderNo = ((String[])request.getAttribute("orderNo"))[0];?
4.?將錯誤中的(String)強制轉換類型修改為 object.toString()
擴展資料:
如果使用Kafka的javaApi向kafka發送消息時提示類似的錯誤:
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to
則我們在發送消息時,需要根據自己發送的消息類型來指定序列化類。比如我們發送字符串消息,在構造生產者時增加以下配置:
Properties props = new Properties();props.put("serializer.class", "kafka.serializer.StringEncoder");
這樣就可以發送字符串消息了
參考資料: