You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Kiran Singh <ki...@gmail.com> on 2015/10/18 12:01:59 UTC

Getting error while reading message

Hi

I am trying to get message from kafka server using hig level consumer API.
But i am getting following exception

"java.lang.ClassCastException: [B cannot be cast to java.lang.String"

Can anyone explain what this means.

Thanks
Kiran Singh

Re: Getting error while reading message

Posted by Selina Tech <sw...@gmail.com>.
I got same error when I send message to Kafka. generally it caused by
deserializer
as Hemant mentioned.
You need to check how the data was send to Kafka, and how is your consumer
deserializer defined.
And you need to check for both Key and value.

the data is the topic might be byte[] type

Sincerely,
Selina

On Sun, Oct 18, 2015 at 3:01 AM, Kiran Singh <ki...@gmail.com> wrote:

> Hi
>
> I am trying to get message from kafka server using hig level consumer API.
> But i am getting following exception
>
> "java.lang.ClassCastException: [B cannot be cast to java.lang.String"
>
> Can anyone explain what this means.
>
> Thanks
> Kiran Singh
>

Re: Getting error while reading message

Posted by Gaurav Agarwal <ga...@gmail.com>.
Are you consuming data in kafkaStream with byte[] argument in generics

On Sun, Oct 18, 2015 at 4:20 PM, Kiran Singh <ki...@gmail.com> wrote:

> Hi Pratapi
>
> I am using following serializer property at producer side:
>
> ("serializer.class", "kafka.serializer.StringEncoder");
>
> And at consumer side i am trying to read data in string. And i am getting
> this error.
>
> Is there any way to write deserializer at consumer side to string?
>
> On Sun, Oct 18, 2015 at 3:48 PM, Pratapi Hemant Patel <
> hemantsonu20@gmail.com> wrote:
>
> > The problem is with your deserializer. Which deserializer are u using.
> > It seems you are getting data as a byte array, and in deserializer u r
> > directly type casting into string.
> >
> > Best Regards,
> > Hemant
> > 9810752184 / 9013982184 <%209013982184>
> > On 18-Oct-2015 3:32 pm, "Kiran Singh" <ki...@gmail.com> wrote:
> >
> > > Hi
> > >
> > > I am trying to get message from kafka server using hig level consumer
> > API.
> > > But i am getting following exception
> > >
> > > "java.lang.ClassCastException: [B cannot be cast to java.lang.String"
> > >
> > > Can anyone explain what this means.
> > >
> > > Thanks
> > > Kiran Singh
> > >
> >
>

Re: Getting error while reading message

Posted by Kiran Singh <ki...@gmail.com>.
Hi Pratapi

I am using following serializer property at producer side:

("serializer.class", "kafka.serializer.StringEncoder");

And at consumer side i am trying to read data in string. And i am getting
this error.

Is there any way to write deserializer at consumer side to string?

On Sun, Oct 18, 2015 at 3:48 PM, Pratapi Hemant Patel <
hemantsonu20@gmail.com> wrote:

> The problem is with your deserializer. Which deserializer are u using.
> It seems you are getting data as a byte array, and in deserializer u r
> directly type casting into string.
>
> Best Regards,
> Hemant
> 9810752184 / 9013982184 <%209013982184>
> On 18-Oct-2015 3:32 pm, "Kiran Singh" <ki...@gmail.com> wrote:
>
> > Hi
> >
> > I am trying to get message from kafka server using hig level consumer
> API.
> > But i am getting following exception
> >
> > "java.lang.ClassCastException: [B cannot be cast to java.lang.String"
> >
> > Can anyone explain what this means.
> >
> > Thanks
> > Kiran Singh
> >
>

Re: Getting error while reading message

Posted by Pratapi Hemant Patel <he...@gmail.com>.
The problem is with your deserializer. Which deserializer are u using.
It seems you are getting data as a byte array, and in deserializer u r
directly type casting into string.

Best Regards,
Hemant
9810752184 / 9013982184
On 18-Oct-2015 3:32 pm, "Kiran Singh" <ki...@gmail.com> wrote:

> Hi
>
> I am trying to get message from kafka server using hig level consumer API.
> But i am getting following exception
>
> "java.lang.ClassCastException: [B cannot be cast to java.lang.String"
>
> Can anyone explain what this means.
>
> Thanks
> Kiran Singh
>