Mark Korzhov
Mark Korzhov

Reputation: 2159

'void' type not allowed here - is there a workaround?

I use the library json-simple.

Object is created in a simple loop (cinema.start(i, j) returns a valid JSON-Object):

JSONObject cinemaJSON = null;
for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                if (cinema.start(i, j) != null)
                    cinemaJSON = cinema.start(i, j);
            }
        }

Then I try to merge two JSON-Objects and print it (cinema2.start("value") returns a valid object, too):

System.out.println(cinemaJSON.putAll(cinema2.start("value")));

And at this point I get the error: 'void' type not allowed here

Are there ways to alternative implementation of my code to make it possible to display the result of the merger of two objects?

Thanks.

Upvotes: 0

Views: 222

Answers (2)

Juned Ahsan
Juned Ahsan

Reputation: 68715

JSONObject putAll returns void and hence sysout statement complains for it.

Just split the statement

System.out.println(cinemaJSON.putAll(cinema2.start("value")));

into two:

cinemaJSON.putAll(cinema2.start("value"));
System.out.println(cinemaJSON);

Upvotes: 2

Ruchira Gayan Ranaweera
Ruchira Gayan Ranaweera

Reputation: 35557

putAll() is a void method(nothing return). So you can try this way

cinemaJSON.putAll(cinema2.start("value"))

Now print

System.out.println(cinemaJSON);

Upvotes: 4

Related Questions