Exception in parsing json to string

I am using java SDk 2.1.4 for n1QL queries but i am getting json parsing exception

bucket
.async()
.query(Query.simple(select("*").from(“travel-sample”).limit(1)))
.flatMap(AsyncQueryResult::rows)
.toBlocking()
.forEach(System.out::println);

can any pne help me on this.

Hi @Arihant
Can you share the exception details?

Method threw ‘java.lang.NullPointerException’ exception. Cannot evaluate com.couchbase.client.java.query.dsl.Expression.toString()

this is the exception i have got. but the same query i am able to get the data in the command line.

The null pointer exception could indicate that the result perhaps is null, can you check for that?

Not sure whats the problem in syntax, but the query is working in command line.

hi @arihant, 2.1.4 N1QL support was experimental and targeted towards a preview release of N1QL, DP4. You should be using 2.2.0 which was released last week, together with a more recent version of N1QL through CB4.0.

But the NullPointerException feels weird to me, can you please post the complete stack trace or at least enough to understand where toString was called?

Also on a side note if you use trave-sample I think you have to escape the bucket name with backticks (use the i() static method from Expression), since otherwise the query engine would interpret the - as a subtraction operator, so: select("*").from(i("travel-sample")).limit(1).

In addition to what @simonbasle recommends, it may make sense to turn up the log level so you can see what string is being sent over to the query service and what the response is.

sure. i will check and get back to you.