JsonParser ArrayIndexOutOfBoundsException when parsing json - java
The following code should work as a JsonParser but it is returning an ArrayIndexOutOfBoundsException even though I check that there are still elements to parse.
public void parseJson(String url) {
try {
InputStream is = new URL(url).openStream();
JsonParser parser = Json.createParser(is);
while (parser.hasNext()) {
Event e = parser.next();
if (e == Event.KEY_NAME) {
if (parser.getString().equals("name") && parser.hasNext()) {
parser.next();
writer = new BufferedWriter(new FileWriter("names.txt"));
writer.write(parser.getString());
}
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
The error produced is such:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4096
at org.glassfish.json.JsonTokenizer.readChar(JsonTokenizer.java:388)
at org.glassfish.json.JsonTokenizer.read(JsonTokenizer.java:98)
at org.glassfish.json.JsonTokenizer.readString(JsonTokenizer.java:124)
at org.glassfish.json.JsonTokenizer.nextToken(JsonTokenizer.java:310)
at org.glassfish.json.JsonParserImpl$StateIterator.nextToken(JsonParserImpl.java:157)
at org.glassfish.json.JsonParserImpl$StateIterator.next(JsonParserImpl.java:182)
at org.glassfish.json.JsonParserImpl.next(JsonParserImpl.java:150)
at proj.Proj2.parseJson(Proj2.java:43)
at proj.Proj1.main(Proj1.java:78)
It parses everything up to when the error is thrown.
Sample JSON that produces error:
[{"id":774,"na":"Hungry Leaf","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1200,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"2608 Erwin Rd, Durham, NC","full_addr":{"addr":"2608 Erwin Rd","addr2":"","city":"Durham","state":"NC","postal_code":"27705-3843"},"city":"Durham","latitude":36.008621,"longitude":-78.94474,"del":1200,"mino":100,"is_delivering":0},{"id":780,"na":"Armadillo Grill","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Mexican","Tex-Mex"],"addr":"439 Glenwood Ave, Raleigh, NC","full_addr":{"addr":"439 Glenwood Ave","addr2":"","city":"Raleigh","state":"NC","postal_code":"27603-1219"},"city":"Raleigh","latitude":35.785754,"longitude":-78.647293,"del":1080,"mino":100,"is_delivering":0},{"id":783,"na":"Chef Mario's Bistro","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":2880,"mino":150,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Sandwiches"],"addr":"2610 Wycliff Rd, Raleigh, NC","full_addr":{"addr":"2610 Wycliff Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27607-3060"},"city":"Raleigh","latitude":35.818683,"longitude":-78.692145,"del":2880,"mino":150,"is_delivering":0},{"id":784,"na":"Chef Mario's Catering","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":4320,"mino":150,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Catering","Italian","Sandwiches"],"addr":"2610 Wycliff Rd, Raleigh, NC","full_addr":{"addr":"2610 Wycliff Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27607-3060"},"city":"Raleigh","latitude":35.818683,"longitude":-78.692145,"del":4320,"mino":150,"is_delivering":0},{"id":786,"na":"D'Nardys Caterers","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1320,"mino":6.55,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Catering","Italian","Sandwiches"],"addr":"314 Madison Grove Pl, Cary, NC","full_addr":{"addr":"314 Madison Grove Pl","addr2":"","city":"Cary","state":"NC","postal_code":"27519-8161"},"city":"Cary","latitude":35.82135,"longitude":-78.854469,"del":1320,"mino":6.55,"is_delivering":0},{"id":787,"na":"Danny's Bar-B-Que","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":2640,"mino":100,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["American","Barbecue"],"addr":"9561 Chapel Hill Rd, Morrisville, NC","full_addr":{"addr":"9561 Chapel Hill Rd","addr2":"","city":"Morrisville","state":"NC","postal_code":"27560-7359"},"city":"Morrisville","latitude":35.805972,"longitude":-78.809315,"del":2640,"mino":100,"is_delivering":1},{"id":792,"na":"Flying Biscuit","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1440,"mino":150,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["Breakfast","Sandwiches"],"addr":"2016 Clark Ave, Raleigh, NC","full_addr":{"addr":"2016 Clark Ave","addr2":"","city":"Raleigh","state":"NC","postal_code":"27605-1604"},"city":"Raleigh","latitude":35.788996,"longitude":-78.659642,"del":1440,"mino":150,"is_delivering":1},{"id":793,"na":"Gateway Restaurant","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1320,"mino":50,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast"],"addr":"2411 Crabtree Blvd, Raleigh, NC","full_addr":{"addr":"2411 Crabtree Blvd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27604-2232"},"city":"Raleigh","latitude":35.805222,"longitude":-78.611873,"del":1320,"mino":50,"is_delivering":0},{"id":796,"na":"Hibachi Xpress","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":720,"mino":150,"can":0}},"allow_tip":1,"allow_asap":1,"addr":"2470 Walnut St, Cary, NC","full_addr":{"addr":"2470 Walnut St","addr2":"","city":"Cary","state":"NC","postal_code":"27518-9212"},"city":"Cary","latitude":35.75113,"longitude":-78.741205,"del":720,"mino":150,"is_delivering":0},{"id":798,"na":"HoneyBaked Ham","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":60,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Sandwiches"],"addr":"5275 Six Forks Rd, Raleigh, NC","full_addr":{"addr":"5275 Six Forks Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27609-4431"},"city":"Raleigh","latitude":35.85326,"longitude":-78.642593,"del":1080,"mino":60,"is_delivering":0},{"id":804,"na":"Moe's Southwest Grill","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Mexican","Tex-Mex"],"addr":"506 Daniels St, Raleigh, NC","full_addr":{"addr":"506 Daniels St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27605-1317"},"city":"Raleigh","latitude":35.791061,"longitude":-78.66118,"del":1080,"mino":100,"is_delivering":0},{"id":806,"na":"Ole Time Barbecue","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":75,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Barbecue"],"addr":"6309 Hillsborough St, Raleigh, NC","full_addr":{"addr":"6309 Hillsborough St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27606-1148"},"city":"Raleigh","latitude":35.787922,"longitude":-78.73851,"del":1080,"mino":75,"is_delivering":0},{"id":811,"na":"The Q Shack","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":180,"mino":40,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Barbecue"],"addr":"North Hills, Raleigh, NC","full_addr":{"addr":"North Hills","addr2":"","city":"Raleigh","state":"NC","postal_code":"27609"},"city":"Raleigh","latitude":35.837521,"longitude":-78.64312,"del":180,"mino":40,"is_delivering":0},{"id":812,"na":"We Cook For You","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":720,"mino":125,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Caribbean","Catering","Sandwiches"],"addr":"1125 Fuller St, Raleigh, NC","full_addr":{"addr":"1125 Fuller St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27603-2217"},"city":"Raleigh","latitude":35.765381,"longitude":-78.650581,"del":720,"mino":125,"is_delivering":0},{"id":813,"na":"WhichWich Superior Sandwiches","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":75,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Sandwiches"],"addr":"4025 Lake Boone Trl, Raleigh, NC","full_addr":{"addr":"4025 Lake Boone Trl","addr2":"","city":"Raleigh","state":"NC","postal_code":"27607-2928"},"city":"Raleigh","latitude":35.815604,"longitude":-78.696541,"del":1080,"mino":75,"is_delivering":0},{"id":820,"na":"Greens","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":6.55,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Italian","Seafood"],"addr":"4120 Main at North Hills St, Raleigh, NC","full_addr":{"addr":"4120 Main at North Hills St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27609-5754"},"city":"Raleigh","latitude":35.837546,"longitude":-78.642515,"del":1080,"mino":6.55,"is_delivering":0},{"id":861,"na":"Catering By Design","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":240,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Catering","Italian","Pizza","Sandwiches"],"addr":"132 Kilmayne Dr, Cary, NC","full_addr":{"addr":"132 Kilmayne Dr","addr2":"","city":"Cary","state":"NC","postal_code":"27511-4465"},"city":"Cary","latitude":35.769451,"longitude":-78.783912,"del":240,"mino":100,"is_delivering":0},{"id":3498,"na":"Z Pizza","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":900,"mino":75,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Pizza","Sandwiches"],"addr":"421 Fayetteville St, Raleigh, NC","full_addr":{"addr":"421 Fayetteville St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27601-1778"},"city":"Raleigh","latitude":35.77467,"longitude":-78.639389,"del":900,"mino":75,"is_delivering":0},{"id":3500,"na":"Artisan Sandwiches & Salads","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":900,"mino":50,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"421 Fayetteville St, Raleigh, NC","full_addr":{"addr":"421 Fayetteville St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27601-1778"},"city":"Raleigh","latitude":35.77467,"longitude":-78.639389,"del":900,"mino":50,"is_delivering":0},{"id":3795,"na":"Chef Mario's Catering Dinner","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":4320,"mino":150,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Asian","Barbecue","Breakfast","Catering","Italian","Jamaican","Mediterranean","Sandwiches","Seafood","Thai"],"addr":"2610 Wycliff Rd, Raleigh, NC","full_addr":{"addr":"2610 Wycliff Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27607-3060"},"city":"Raleigh","latitude":35.818683,"longitude":-78.692145,"del":4320,"mino":150,"is_delivering":0},{"id":3895,"na":"A Catered Affair","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":720,"mino":125,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Asian","Breakfast","Catering","Italian","Jamaican","Sandwiches"],"addr":"1125 Fuller St, Raleigh, NC","full_addr":{"addr":"1125 Fuller St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27603-2217"},"city":"Raleigh","latitude":35.765381,"longitude":-78.650581,"del":720,"mino":125,"is_delivering":0},{"id":4011,"na":"Neomonde Mediterranean","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1260,"mino":125,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Breakfast","Mediterranean","Sandwiches"],"addr":"9650 Strickland Rd, Raleigh, NC","full_addr":{"addr":"9650 Strickland Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27615-1937"},"city":"Raleigh","del":1260,"mino":125,"is_delivering":0},{"id":4425,"na":"Dorry's Downtown Deli","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1320,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"211 E Chatham St, Cary, NC","full_addr":{"addr":"211 E Chatham St","addr2":"","city":"Cary","state":"NC","postal_code":"27511-3427"},"city":"Cary","latitude":35.787534,"longitude":-78.777666,"del":1320,"mino":100,"is_delivering":0},{"id":4427,"na":"Pogo","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":180,"mino":40,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"201 E Hargett St, Raleigh, NC","full_addr":{"addr":"201 E Hargett St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27601-1437"},"city":"Raleigh","latitude":35.778141,"longitude":-78.635834,"del":180,"mino":40,"is_delivering":0},{"id":4428,"na":"Chick-fil-A","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1200,"mino":200,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Sandwiches"],"addr":"1803 N Harrison Ave, Cary, NC","full_addr":{"addr":"1803 N Harrison Ave","addr2":"","city":"Cary","state":"NC","postal_code":"27513-2408"},"city":"Cary","latitude":35.828831,"longitude":-78.769402,"del":1200,"mino":200,"is_delivering":0},{"id":6142,"na":"Spartacus Restaurant","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1200,"mino":300,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Mediterranean","Sandwiches"],"addr":"4139 Old Chapel Hill Rd, Durham, NC","full_addr":{"addr":"4139 Old Chapel Hill Rd","addr2":"","city":"Durham","state":"NC","postal_code":"27707-5057"},"city":"Durham","del":1200,"mino":300,"is_delivering":0},{"id":7776,"na":"Firehouse Subs","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":120,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"1539 Us Highway 70 E, Garner, NC","full_addr":{"addr":"1539 Us Highway 70 E","addr2":"","city":"Garner","state":"NC","postal_code":"27529"},"city":"Garner","del":120,"mino":100,"is_delivering":0},{"id":7985,"na":"Ben & Jerry's Ice Cream","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":2880,"mino":200,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["American","Bakery","Ice Cream"],"addr":"102 W Franklin St, Chapel Hill, NC","full_addr":{"addr":"102 W Franklin St","addr2":"","city":"Chapel Hill","state":"NC","postal_code":"27516-2516"},"city":"Chapel Hill","latitude":35.91304,"longitude":-79.056091,"del":2880,"mino":200,"is_delivering":1},{"id":10509,"na":"Catering By Design - Dinner","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":240,"mino":6.55,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Catering","Italian","Sandwiches","Seafood"],"addr":"132 Kilmayne Dr, Cary, NC","full_addr":{"addr":"132 Kilmayne Dr","addr2":"","city":"Cary","state":"NC","postal_code":"27511-4465"},"city":"Cary","latitude":35.769451,"longitude":-78.783912,"del":240,"mino":6.55,"is_delivering":1},{"id":12715,"na":"Top This Cafe # The Atrium","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":45,"mino":0,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"2501 Blue Ridge Rd, Raleigh, NC","full_addr":{"addr":"2501 Blue Ridge Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27607-6436"},"city":"Raleigh","latitude":35.814449,"longitude":-78.705399,"del":45,"mino":0,"is_delivering":0},{"id":12724,"na":"Donovan's Dish","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1200,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Catering","Sandwiches"],"addr":"1040 Buck Jones Rd, Raleigh, NC","full_addr":{"addr":"1040 Buck Jones Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27606-3323"},"city":"Raleigh","latitude":35.770224,"longitude":-78.739941,"del":1200,"mino":100,"is_delivering":0},{"id":12739,"na":"Lubrano's Ristorante Italiano","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1200,"mino":125,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["Italian"],"addr":"101 Keybridge Dr, Morrisville, NC","full_addr":{"addr":"101 Keybridge Dr","addr2":"","city":"Morrisville","state":"NC","postal_code":"27560-5911"},"city":"Morrisville","latitude":35.819771,"longitude":-78.822189,"del":1200,"mino":125,"is_delivering":1},{"id":23709,"na":"DeMarco's Restaurant & Bar","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1260,"mino":125,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["Italian"],"addr":"3607 Falls River Ave, Raleigh, NC","full_addr":{"addr":"3607 Falls River Ave","addr2":"","city":"Raleigh","state":"NC","postal_code":"27614-7359"},"city":"Raleigh","latitude":35.930141,"longitude":-78.564522,"del":1260,"mino":125,"is_delivering":1},{"id":23710,"na":"Green Planet Catering","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":4200,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Catering","Sandwiches"],"addr":"218 S Blount St, Raleigh, NC","full_addr":{"addr":"218 S Blount St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27601-1408"},"city":"Raleigh","latitude":35.777495,"longitude":-78.63662,"del":4200,"mino":100,"is_delivering":0},{"id":23815,"na":"Capital Center Catering","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":960,"mino":150,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Bakery","Catering","Italian","Sandwiches"],"addr":"217 E Main St, Clayton, NC","full_addr":{"addr":"217 E Main St","addr2":"","city":"Clayton","state":"NC","postal_code":"27520-2449"},"city":"Clayton","latitude":35.652088,"longitude":-78.458515,"del":960,"mino":150,"is_delivering":0},{"id":23817,"na":"Firewurst","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":960,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Sandwiches"],"addr":"8531 Brier Creek Pky, Raleigh, NC","full_addr":{"addr":"8531 Brier Creek Pky","addr2":"","city":"Raleigh","state":"NC","postal_code":"27617-7333"},"city":"Raleigh","latitude":35.905433,"longitude":-78.786068,"del":960,"mino":100,"is_delivering":0},{"id":32244,"na":"Don Rio's Southwest Catering","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":720,"mino":125,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Mexican","Tex-Mex"],"addr":"3607 Falls River Ave, Raleigh, NC","full_addr":{"addr":"3607 Falls River Ave","addr2":"","city":"Raleigh","state":"NC","postal_code":"27614-7359"},"city":"Raleigh","latitude":35.930141,"longitude":-78.564522,"del":720,"mino":125,"is_delivering":0}]
It seems this was a bug in version 1.0.1. Here's another thread that talks about it. The JsonTokenizer class has changed pretty dramatically since then. Upgrade to 1.0.2 and you will be fine.
Related
How to get the method to return and print in main? Java
I've written the whole program, but I still can't get the discount to apply to the second print. Here is my code: public static void main(String[] args) { // create array Book[] bookArray = new Book[6]; // use parameterized constructor to create books bookArray[0] = new Book("Java Programming", "Liang", 1320, 145.00); bookArray[1] = new Book("Horton Hears a Who!", "Dr. Suess", 72, 19.99); bookArray[2] = new Book("The Hobbit", "Tolkien", 320, 9.25); bookArray[3] = new Book("Born a Crime", "Noah", 304, 17.33); // use no-arg constructor to create books bookArray[4] = new Book(); bookArray[5] = new Book(); // foreach to print for (Book book: bookArray) { System.out.println(book); } System.out.println(); finishArray(bookArray); System.out.println("Books after completing library and 40% discount"); for (Book book: bookArray) { System.out.println(book); } System.out.println("Most Expensive book after the discounts:\n" + reduceBooks(bookArray)); System.out.println("Size of Library: " + bookArray.length + " books"); } public static void finishArray(Book bookArray[]) { Book book; book = bookArray[4]; book.setTitle("Dark Territory"); book.setAuthor("Kaplan"); book.setPages(352); book.setPrice(11.24); book = bookArray[5]; book.setTitle("Born to Run"); book.setAuthor("Springsteen"); book.setPages(508); book.setPrice(12.17); } public static Book reduceBooks(Book bookArray[]) { Book most = bookArray[0]; for (int i = 0; i < bookArray.length; i++) { Book book = bookArray[i]; // see if this book is more expensive than current most if(book.getPrice() > most.getPrice()) { most = book; } // reduce price book.setPrice(book.getPrice() * 0.6); } return most; // return most expensive } } Here's my output which as you can see the discount does not apply to the second printing: Title: Java Programming Author: Liang Pages: 1320 Price: 145.00 Title: Horton Hears a Who! Author: Dr. Suess Pages: 72 Price: 19.99 Title: The Hobbit Author: Tolkien Pages: 320 Price: 9.25 Title: Born a Crime Author: Noah Pages: 304 Price: 17.33 Title: null Author: null Pages: 0 Price: 0.00 Title: null Author: null Pages: 0 Price: 0.00 Books after completing library and 40% discount Title: Java Programming Author: Liang Pages: 1320 Price: 145.00 Title: Horton Hears a Who! Author: Dr. Suess Pages: 72 Price: 19.99 Title: The Hobbit Author: Tolkien Pages: 320 Price: 9.25 Title: Born a Crime Author: Noah Pages: 304 Price: 17.33 Title: Dark Territory Author: Kaplan Pages: 352 Price: 11.24 Title: Born to Run Author: Springsteen Pages: 508 Price: 12.17 Most Expensive book after the discounts: Title: Java Programming Author: Liang Pages: 1320 Price: 87.00 Size of Library: 6 books Also, these are the instructions for the reduceBooks(), everything must be done in that method- In reduceBooks(): this method returns a Book instance. use a loop (any type) to reduce the price of every book in the array by 40%. determine the most expensive book after the discounts and return this book to main.
You should apply discount before second print. Also, do not forget to remove reducing price code from reduceBooks or else you'll reduce price twice. Here is an example how you can do it: // first print applyDiscount(bookArray); // second print public static void applyDiscount(Book bookArray[]) { for (int i = 0; i < bookArray.length; i++) { Book book = bookArray[i]; // reduce price book.setPrice(book.getPrice() * 0.6); } }
Pass data from 1st Activity to Fragments using Adapter
I'm able to pass data from 1st activity to 2nd activity but I decided to add Fragments in my 2nd activity and now it's not working. I'm completely new to Android Studio, I tried to search for solution but I can't find one. I'm getting an error in the logcat java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.galila/com.example.galila.MainDetails}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference Here's my Main Activity (1st Activity) RecyclerView mainRecycler, mpRecycler; MainAdapter mainAdapter; MpAdapter mpAdapter; EditText searchView; CharSequence search=""; #Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); searchView = findViewById(R.id.search); mainRecycler = findViewById(R.id.main_recycler); mpRecycler = findViewById(R.id.mp_recycler); mainRecycler(); mpRecycler(); } private void mainRecycler() { mainRecycler.setHasFixedSize(true); mainRecycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)); final ArrayList<MainHelperClass> mainLocations = new ArrayList<>(); mainLocations.add(new MainHelperClass(R.drawable.tondolbeach, R.drawable.tondol_beach1, R.drawable.tondol_beach2, R.drawable.tondol_beach3, R.drawable.tondol_beach4, "Tondol Beach", "Anda, Pangasinan", "Tondol Beach is located at the northern tip of Anda, an island municipality that used to be accessible only by boat across the narrow Catubig Channel. What makes Tondol unique is its long, shallow nature. There is a considerable amount of marine life besides starfish and crabs on the shallow beach.", "Manila - Tondol Beach", "5 hrs 19 mins (291.1 km)", "Swimming", "Sightseeing", "Boat Ride", "Eat Seafoods", "Party")); mainLocations.add(new MainHelperClass(R.drawable.saintspeterandpaul, R.drawable.calasiao_church1, R.drawable.calasiao_church2, R.drawable.calasiao_church3, R.drawable.calasiao_church4, "Calasiao Church", "Calasiao, Pangasinan", "The Saints Peter and Paul Parish Church (Iglesia Parroquial de los Pedro y Pablo), commonly know as Calasiao Church is a baroque church located in Poblacion West, Calasiao, Pangasinan, Philippines. It was founded in 1588 by the Spaniards. It is 88.3 meter long, 25 meters wide and 27.3 meters high. It was declared as a National Treasure in 2001.", "Manila - Calasiao", "3 hrs 26 mins (211.6 km)", "Attend Mass", "Souvenirs", "Local Foods", "Sightseeing", "Fiesta")); mainLocations.add(new MainHelperClass(R.drawable.manaoagchurch, R.drawable.manaoag_church1, R.drawable.manaoag_church2, R.drawable.manaoag_church3, R.drawable.manaoag_church4, "Manaoag Church", "Manaoag, Pangasinan", "Our Lady of Manaoag is a top-rated destination in the Philippines for Catholic travelers around the world. 'Our Lady of the Most Holy Rosary of Manaoag' or known as 'Our Lady of Manaoag' is one of the most visited church in Pangasinan. It was built in the 17th century. Thousands of people come to the province every year to experience the spiritual nature of the area and take in different historical and religious attractions.", "Manila - Manaoag Church", "3 hrs 3 mins (198.9 km)", "Attend Mass", "Souvenirs", "Local Foods", "Sightseeing", "Fiesta")); mainLocations.add(new MainHelperClass(R.drawable.patarbeach, R.drawable.patar_beach1, R.drawable.patar_beach2, R.drawable.patar_beach3, R.drawable.patar_beach4, "Patar Beach", "Bolinao, Pangasinan", "Bolinao is known for a number of prestine beaches, the most popular one is the Patar Beach which dubbed as the Boracay of the North, located on the western coast along the South China Sea southwest of the town proper. Patar Beach is a creamy white sand beach that slopes gradually from shore making it good for swimming.", "Manila - Patar Beach", "5 hrs 25 mins (298.4 km)", "Swimming", "Sightseeing", "Boat Ride", "Eat Seafoods", "Party")); mainLocations.add(new MainHelperClass(R.drawable.hundredisland, R.drawable.hundred_island_gallery1, R.drawable.hundred_island_gallery2, R.drawable.hundred_island_gallery3, R.drawable.hundred_island_gallery4, "Hundred Islands", "Alaminos, Pangasinan", "The Hundred Islands National Park is the first national park and a protected area located in Alaminos, Pangasinan in the Northern Philippines. The islands, totaling 124 at low tide and 123 at high tide, are scattered in Lingayen Gulf covering an area of 16.76 square kilometers (6.47 sq mi.). Only three of them have been developed for tourism: Governor Island, Quezon Island and Childrens Island.", "Manila - Hundred Islands", "3 hrs 10 mins (205 km)", "Swimming", "Island Hoping", "Snorkeling", "Kayaking", "Zipline")); mainLocations.add(new MainHelperClass(R.drawable.bolinao_lighthouse, R.drawable.bolinao_lighthouse_1, R.drawable.bolinao_lighthouse_2, R.drawable.bolinao_lighthouse_3, R.drawable.bolinao_lighthouse_4, "Bolinao Lighthouse", "Bolinao, Pangasinan", "The Cape of Bolinao Lighthouse at Patar rises 351 ft (107 m) above sea level atop Punta Piedra Point, a towering hill of solid rock which is the sharp point of Cape Bolinao itself. It was built by the Americans in 1903. The lighthouse provides a panoramic view of a portion of the 1269 hectares Cape Bolinao Dendro Thermal Ipil-Ipil Plantation on a land area where archeological excavations have revealed relics from 14th to 15th centuries.", "Manila - Bolinao Lighthouse", "5 hrs 20 mins (284.1 km)", "Sightseeing", "Exploration", "Local Foods", "Photoshoot", "Souvenirs")); mainLocations.add(new MainHelperClass(R.drawable.st_james_the_great, R.drawable.st_james_the_great_1, R.drawable.st_james_the_great_2, R.drawable.st_james_the_great_3, R.drawable.st_james_the_great_4, "St. James the Great Church", "Bolinao, Pangasinan", "The Saint James the Great Parish Church is a Spanish colonial church located at Brgy. Germinal in Bolinao, Pangasinan. The church was made out of black coral stones. It is one of the oldest church in Pangasinan, it was constructed in 1600s and survived multiple natural and manmade calamities like 1788 earthquake, 1819 fire and 2009 typhoon.", "Manila - St. James the Great Church", "5 hrs 6 mins (286 km)", "Attend Mass", "Souvenirs", "Local Foods", "Sightseeing", "Fiesta")); mainLocations.add(new MainHelperClass(R.drawable.bolinao_falls, R.drawable.bolinao_falls_1, R.drawable.bolinao_falls_2, R.drawable.bolinao_falls_3, R.drawable.bolinao_falls_4, "Bolinao Falls", "Bolinao, Pangasinan", "Bolinao Falls is a short waterfall which is a result varying elevations of the Balingasay River, thus the water falls down to a pool of water located on a lower elevation. Bolinao Falls is about 19 kilometers away from Bolinao town proper. Its divided into three waterfalls, all located along the Bolinao river. Each falls has different views and features.", "Manila - Bolinao Falls", "5 hrs 3 mins (277.3 km)", "Cliff Diving", "Swimming", "Sightseeing", "Exploration", "Photoshoot")); mainLocations.add(new MainHelperClass(R.drawable.enchanted_cave, R.drawable.enchanted_cave_1, R.drawable.enchanted_cave_2, R.drawable.enchanted_cave_3, R.drawable.enchanted_cave_4, "Enchanted Cave", "Bolinao, Pangasinan", "Enchanted Cave is one of the must visit attractions in Bolinao, Pangasinan. The name itself portrays its mystical beauty. The entire place is really enchanted since it is like a huge coral reef that emerged underwater. The water inside the cave is clear and not salty. Its depth is estimated around 3-6 ft. Enchanted Cave offers underground pool with crystal clear spring water, natural sea rock hill terrain, and etc.", "Manila - Enchanted Cave", "5 hrs 26 mins (297.6 km)", "Swimming", "Sightseeing", "Exploration", "Photoshoot", "Local Foods")); mainLocations.add(new MainHelperClass(R.drawable.tondaligan_beach, R.drawable.tondaligan_beach_1, R.drawable.tondaligan_beach_2, R.drawable.tondaligan_beach_3, R.drawable.tondaligan_beach_4, "Tondaligan Beach", "Dagupan, Pangasinan", "One of the most visited beach in Dagupan. Its fine sands and numerous coconut trees attract people all year-round, the beach area is quite large so no need to worry about running out of good spots.", "Manila - Tondaligan Beach", "3 hrs 30 mins (219.2 km)", "Swimming", "Boat Ride", "Sightseeing", "Eat Seafoods", "Party")); mainAdapter = new MainAdapter(mainLocations, getApplicationContext()); mainRecycler.setAdapter(mainAdapter); searchView.addTextChangedListener(new TextWatcher() { #Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } #Override public void onTextChanged(CharSequence charSequence, int start, int before, int count) { mainAdapter.getFilter().filter(charSequence); search = charSequence; } #Override public void afterTextChanged(Editable s) { } }); } private void mpRecycler() { mpRecycler.setHasFixedSize(true); mpRecycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); ArrayList<MpHelperClass> mpLocations = new ArrayList<>(); mpLocations.add(new MpHelperClass(R.drawable.hundredisland, R.drawable.hundred_island_gallery1, R.drawable.hundred_island_gallery2, R.drawable.hundred_island_gallery3, R.drawable.hundred_island_gallery4, "Hundred Islands", "Alaminos, Pangasinan", "The Hundred Islands National Park is the first national park and a protected area located in Alaminos, Pangasinan in the Northern Philippines. The islands, totaling 124 at low tide and 123 at high tide, are scattered in Lingayen Gulf covering an area of 16.76 square kilometers (6.47 sq mi.). Only three of them have been developed for tourism: Governor Island, Quezon Island and Childrens Island.", "Ratings: 4.5", "Manila - Hundred Islands", "3 hrs 10 mins (205 km)", "Swimming", "Island Hoping", "Snorkeling", "Kayaking", "Zipline")); mpLocations.add(new MpHelperClass(R.drawable.patarbeach, R.drawable.patar_beach1, R.drawable.patar_beach2, R.drawable.patar_beach3, R.drawable.patar_beach4, "Patar Beach", "Bolinao, Pangasinan", "Bolinao is known for a number of prestine beaches, the most popular one is the Patar Beach which dubbed as the Boracay of the North, located on the western coast along the South China Sea southwest of the town proper. Patar Beach is a creamy white sand beach that slopes gradually from shore making it good for swimming.", "Ratings: 4.5", "Manila - Patar Beach", "5 hrs 25 mins (298.4 km)", "Swimming", "Sightseeing", "Boat Ride", "Eat Seafoods", "Party")); mpLocations.add(new MpHelperClass(R.drawable.bolinao_falls, R.drawable.bolinao_falls_1, R.drawable.bolinao_falls_2, R.drawable.bolinao_falls_3, R.drawable.bolinao_falls_4, "Bolinao Falls", "Bolinao, Pangasinan", "Bolinao Falls is a short waterfall which is a result varying elevations of the Balingasay River, thus the water falls down to a pool of water located on a lower elevation. Bolinao Falls is about 19 kilometers away from Bolinao town proper. Its divided into three waterfalls, all located along the Bolinao river. Each falls has different views and features.", "Ratings: 4.5", "Manila - Bolinao Falls", "5 hrs 3 mins (277.3 km)", "Cliff Diving", "Swimming", "Sightseeing", "Exploration", "Photoshoot")); mpLocations.add(new MpHelperClass(R.drawable.tondolbeach, R.drawable.tondol_beach1, R.drawable.tondol_beach2, R.drawable.tondol_beach3, R.drawable.tondol_beach4, "Tondol Beach", "Anda, Pangasinan", "Tondol Beach is located at the northern tip of Anda, an island municipality that used to be accessible only by boat across the narrow Catubig Channel. What makes Tondol unique is its long, shallow nature. There is a considerable amount of marine life besides starfish and crabs on the shallow beach.", "Ratings: 4", "Manila - Tondol Beach", "5 hrs 19 mins (291.1 km)", "Swimming", "Sightseeing", "Boat Ride", "Eat Seafoods", "Party")); mpLocations.add(new MpHelperClass(R.drawable.manaoagchurch, R.drawable.manaoag_church1, R.drawable.manaoag_church2, R.drawable.manaoag_church3, R.drawable.manaoag_church4, "Manaoag Church", "Manaoag, Pangasinan", "Our Lady of Manaoag is a top-rated destination in the Philippines for Catholic travelers around the world. 'Our Lady of the Most Holy Rosary of Manaoag' or known as 'Our Lady of Manaoag' is one of the most visited church in Pangasinan. It was built in the 17th century. Thousands of people come to the province every year to experience the spiritual nature of the area and take in different historical and religious attractions.", "Ratings: 4", "Manila - Manaoag Church", "3 hrs 3 mins (198.9 km)", "Attend Mass", "Souvenirs", "Local Foods", "Sightseeing", "Fiesta")); mpLocations.add(new MpHelperClass(R.drawable.st_james_the_great, R.drawable.st_james_the_great_1, R.drawable.st_james_the_great_2, R.drawable.st_james_the_great_3, R.drawable.st_james_the_great_4, "St. James the Great Church", "Bolinao, Pangasinan", "The Saint James the Great Parish Church is a Spanish colonial church located at Brgy. Germinal in Bolinao, Pangasinan. The church was made out of black coral stones. It is one of the oldest church in Pangasinan, it was constructed in 1600s and survived multiple natural and manmade calamities like 1788 earthquake, 1819 fire and 2009 typhoon.", "Ratings: 4", "Manila - St. James the Great Church", "5 hrs 6 mins (286 km)", "Attend Mass", "Souvenirs", "Local Foods", "Sightseeing", "Fiesta")); mpLocations.add(new MpHelperClass(R.drawable.enchanted_cave, R.drawable.enchanted_cave_1, R.drawable.enchanted_cave_2, R.drawable.enchanted_cave_3, R.drawable.enchanted_cave_4, "Enchanted Cave", "Bolinao, Pangasinan", "Enchanted Cave is one of the must visit attractions in Bolinao, Pangasinan. The name itself portrays its mystical beauty. The entire place is really enchanted since it is like a huge coral reef that emerged underwater. The water inside the cave is clear and not salty. Its depth is estimated around 3-6 ft. Enchanted Cave offers underground pool with crystal clear spring water, natural sea rock hill terrain, and etc.", "Ratings: 4", "Manila - Enchanted Cave", "5 hrs 26 mins (297.6 km)", "Swimming", "Sightseeing", "Exploration", "Photoshoot", "Local Foods")); mpLocations.add(new MpHelperClass(R.drawable.bolinao_lighthouse, R.drawable.bolinao_lighthouse_1, R.drawable.bolinao_lighthouse_2, R.drawable.bolinao_lighthouse_3, R.drawable.bolinao_lighthouse_4, "Bolinao Lighthouse", "Bolinao, Pangasinan", "The Cape of Bolinao Lighthouse at Patar rises 351 ft (107 m) above sea level atop Punta Piedra Point, a towering hill of solid rock which is the sharp point of Cape Bolinao itself. It was built by the Americans in 1903. The lighthouse provides a panoramic view of a portion of the 1269 hectares Cape Bolinao Dendro Thermal Ipil-Ipil Plantation on a land area where archeological excavations have revealed relics from 14th to 15th centuries.", "Ratings: 4", "Manila - Bolinao Lighthouse", "5 hrs 20 mins (284.1 km)", "Sightseeing", "Exploration", "Local Foods", "Photoshoot", "Souvenirs")); mpLocations.add(new MpHelperClass(R.drawable.tondaligan_beach, R.drawable.tondaligan_beach_1, R.drawable.tondaligan_beach_2, R.drawable.tondaligan_beach_3, R.drawable.tondaligan_beach_4, "Tondaligan Beach", "Dagupan, Pangasinan", "One of the most visited beach in Dagupan. Its fine sands and numerous coconut trees attract people all year-round, the beach area is quite large so no need to worry about running out of good spots.", "Ratings: 3.5", "Manila - Tondaligan Beach", "3 hrs 30 mins (219.2 km)", "Swimming", "Boat Ride", "Sightseeing", "Eat Seafoods", "Party")); mpLocations.add(new MpHelperClass(R.drawable.saintspeterandpaul, R.drawable.calasiao_church1, R.drawable.calasiao_church2, R.drawable.calasiao_church3, R.drawable.calasiao_church4, "Calasiao Church", "Calasiao, Pangasinan", "The Saints Peter and Paul Parish Church (Iglesia Parroquial de los Pedro y Pablo), commonly know as Calasiao Church is a baroque church located in Poblacion West, Calasiao, Pangasinan, Philippines. It was founded in 1588 by the Spaniards. It is 88.3 meter long, 25 meters wide and 27.3 meters high. It was declared as a National Treasure in 2001.", "Ratings: 3.5", "Manila - Calasiao", "3 hrs 26 mins (211.6 km)", "Attend Mass", "Souvenirs", "Local Foods", "Sightseeing", "Fiesta")); mpAdapter = new MpAdapter(mpLocations, getApplicationContext()); mpRecycler.setAdapter(mpAdapter); } } Here's my AdapterClass public class MainAdapter extends RecyclerView.Adapter<MainAdapter.MainViewHolder> implements Filterable { ArrayList<MainHelperClass> mainLocations; ArrayList<MainHelperClass> filteredMainLocations; Context context; public MainAdapter(ArrayList<MainHelperClass> mainLocations, Context context) { this.mainLocations = mainLocations; this.context = context; this.filteredMainLocations = mainLocations; } #NonNull #Override public MainViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.main_card_design,parent,false); MainViewHolder mainViewHolder = new MainViewHolder(view); return mainViewHolder; } #Override public void onBindViewHolder(#NonNull MainViewHolder holder, int position) { final MainHelperClass mainHelperClass = filteredMainLocations.get(position); holder.image.setImageResource(mainHelperClass.getImage()); holder.gallery1.setImageResource(mainHelperClass.getGallery1()); holder.gallery2.setImageResource(mainHelperClass.getGallery2()); holder.gallery3.setImageResource(mainHelperClass.getGallery3()); holder.gallery4.setImageResource(mainHelperClass.getGallery4()); holder.placeName.setText(mainHelperClass.getPlaceName()); holder.location.setText(mainHelperClass.getLocation()); holder.description.setText(mainHelperClass.getDescription()); holder.distance.setText(mainHelperClass.getDistance()); holder.km.setText(mainHelperClass.getKm()); holder.todo1.setText(mainHelperClass.getTodo1()); holder.todo2.setText(mainHelperClass.getTodo2()); holder.todo3.setText(mainHelperClass.getTodo3()); holder.todo4.setText(mainHelperClass.getTodo4()); holder.todo5.setText(mainHelperClass.getTodo5()); holder.itemView.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { Intent intent = new Intent(context, MainDetails.class); intent.putExtra("image", mainHelperClass.getImage()); intent.putExtra("gallery1", mainHelperClass.getGallery1()); intent.putExtra("gallery2", mainHelperClass.getGallery2()); intent.putExtra("gallery3", mainHelperClass.getGallery3()); intent.putExtra("gallery4", mainHelperClass.getGallery4()); intent.putExtra("place name", mainHelperClass.getPlaceName()); intent.putExtra("location", mainHelperClass.getLocation()); intent.putExtra("description", mainHelperClass.getDescription()); intent.putExtra("distance", mainHelperClass.getDistance()); intent.putExtra("km", mainHelperClass.getKm()); intent.putExtra("todo1", mainHelperClass.getTodo1()); intent.putExtra("todo2", mainHelperClass.getTodo2()); intent.putExtra("todo3", mainHelperClass.getTodo3()); intent.putExtra("todo4", mainHelperClass.getTodo4()); intent.putExtra("todo5", mainHelperClass.getTodo5()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } }); } #Override public int getItemCount() { return filteredMainLocations.size(); } public static class MainViewHolder extends RecyclerView.ViewHolder{ ImageView image, gallery1, gallery2, gallery3, gallery4; TextView placeName, location, description, distance, km, todo1, todo2, todo3, todo4, todo5; public MainViewHolder(#NonNull View itemView) { super(itemView); image = itemView.findViewById(R.id.main_image); gallery1 = itemView.findViewById(R.id.main_gallery_1); gallery2 = itemView.findViewById(R.id.main_gallery_2); gallery3 = itemView.findViewById(R.id.main_gallery_3); gallery4 = itemView.findViewById(R.id.main_gallery_4); placeName = itemView.findViewById(R.id.main_place_name); location = itemView.findViewById(R.id.main_location); description = itemView.findViewById(R.id.main_description); distance = itemView.findViewById(R.id.main_distance); km = itemView.findViewById(R.id.main_km); todo1 = itemView.findViewById(R.id.main_todo1); todo2 = itemView.findViewById(R.id.main_todo2); todo3 = itemView.findViewById(R.id.main_todo3); todo4 = itemView.findViewById(R.id.main_todo4); todo5 = itemView.findViewById(R.id.main_todo5); } } public Filter getFilter() { return new Filter() { #Override protected FilterResults performFiltering(CharSequence charSequence) { String key = charSequence.toString(); if (key.isEmpty()) { filteredMainLocations = mainLocations; }else { ArrayList<MainHelperClass> isFiltered = new ArrayList<>(); for (MainHelperClass row : mainLocations) { if (row.getPlaceName().toLowerCase().contains(key.toLowerCase())) { isFiltered.add(row); } else if (row.getLocation().toLowerCase().contains(key.toLowerCase())) { isFiltered.add(row); } } filteredMainLocations = isFiltered; } FilterResults filterResults = new FilterResults(); filterResults.values = filteredMainLocations; return filterResults; } #Override protected void publishResults(CharSequence constraint, FilterResults filterResults) { filteredMainLocations = (ArrayList<MainHelperClass>) filterResults.values; notifyDataSetChanged(); } }; } } Here's my DetailsActivity (2nd Activity), I want to create Fragments here for navigation purposes public class MainDetails extends AppCompatActivity { ImageView image, gallery1, gallery2, gallery3, gallery4; TextView placeName, location, description, distance, km, todo1, todo2, todo3, todo4, todo5; Button descriptionFragment, distanceFragment, galleryFragment, todoFragment; #Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_details); descriptionFragment = (Button) findViewById(R.id.description_fragment); distanceFragment = (Button)findViewById(R.id.distance_fragment); galleryFragment = (Button)findViewById(R.id.gallery_fragment); todoFragment = (Button)findViewById(R.id.todo_fragment); descriptionFragment.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { setFragment(new DescriptionFragment()); } }); distanceFragment.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { setFragment(new DistanceFragment()); } }); galleryFragment.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { setFragment(new GalleryFragment()); } }); todoFragment.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { setFragment(new TodoFragment()); } }); image = (ImageView)findViewById(R.id.main_image_details); gallery1 = (ImageView)findViewById(R.id.main_gallery_details_1); gallery2 = (ImageView)findViewById(R.id.main_gallery_details_2); gallery3 = (ImageView)findViewById(R.id.main_gallery_details_3); gallery4 = (ImageView)findViewById(R.id.main_gallery_details_4); placeName = (TextView)findViewById(R.id.main_place_name_details); location = (TextView)findViewById(R.id.main_loc_details); description = (TextView)findViewById(R.id.main_desc_details); distance = (TextView)findViewById(R.id.main_distance_details); km = (TextView)findViewById(R.id.main_km_details); todo1 = (TextView)findViewById(R.id.main_todo1_details); todo2 = (TextView)findViewById(R.id.main_todo2_details); todo3 = (TextView)findViewById(R.id.main_todo3_details); todo4 = (TextView)findViewById(R.id.main_todo4_details); todo5 = (TextView)findViewById(R.id.main_todo5_details); image.setImageResource(getIntent().getIntExtra("image", 0)); gallery1.setImageResource(getIntent().getIntExtra("gallery1", 0)); gallery2.setImageResource(getIntent().getIntExtra("gallery2", 0)); gallery3.setImageResource(getIntent().getIntExtra("gallery3", 0)); gallery4.setImageResource(getIntent().getIntExtra("gallery4", 0)); placeName.setText(getIntent().getStringExtra("place name")); location.setText(getIntent().getStringExtra("location")); description.setText(getIntent().getStringExtra("description")); distance.setText(getIntent().getStringExtra("distance")); km.setText(getIntent().getStringExtra("km")); todo1.setText(getIntent().getStringExtra("todo1")); todo2.setText(getIntent().getStringExtra("todo2")); todo3.setText(getIntent().getStringExtra("todo3")); todo4.setText(getIntent().getStringExtra("todo4")); todo5.setText(getIntent().getStringExtra("todo5")); final ImageView image1 = (ImageView) findViewById(R.id.main_image_details); final ImageView gallery1 = (ImageView) findViewById(R.id.main_gallery_details_1); gallery1.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { image1.setImageResource(getIntent().getIntExtra("gallery1", 0)); } }); final ImageView image2 = (ImageView) findViewById(R.id.main_image_details); final ImageView gallery2 = (ImageView) findViewById(R.id.main_gallery_details_2); gallery2.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { image2.setImageResource(getIntent().getIntExtra("gallery2", 0)); } }); final ImageView image3 = (ImageView) findViewById(R.id.main_image_details); final ImageView gallery3 = (ImageView) findViewById(R.id.main_gallery_details_3); gallery3.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { image3.setImageResource(getIntent().getIntExtra("gallery3", 0)); } }); final ImageView image4 = (ImageView) findViewById(R.id.main_image_details); final ImageView gallery4 = (ImageView) findViewById(R.id.main_gallery_details_4); gallery4.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { image4.setImageResource(getIntent().getIntExtra("gallery4", 0)); } }); } private void setFragment(Fragment Fragment) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.flFragment, Fragment); fragmentTransaction.commit(); } }
You need to use Bundle for passing data from activity to Fragment Here is a sample code : Create Bundle object and assign values like this Bundle bundle = new Bundle(); bundle.putString("image", mainHelperClass.getImage()); bundle.putString("gallery1", mainHelperClass.getGallery1()); bundle.putString("gallery2", mainHelperClass.getGallery2()); bundle.putString("gallery3", mainHelperClass.getGallery3()); bundle.putString("gallery4", mainHelperClass.getGallery4()); bundle.putString("place name", mainHelperClass.getPlaceName()); bundle.putString("location", mainHelperClass.getLocation()); bundle.putString("description", mainHelperClass.getDescription()); bundle.putString("distance", mainHelperClass.getDistance()); bundle.putString("km", mainHelperClass.getKm()); bundle.putString("todo1", mainHelperClass.getTodo1()); bundle.putString("todo2", mainHelperClass.getTodo2()); bundle.putString("todo3", mainHelperClass.getTodo3()); bundle.putString("todo4", mainHelperClass.getTodo4()); bundle.putString("todo5", mainHelperClass.getTodo5()); Call the Fragment and pass arguments from Adapter class YourFragment fragment = new YourFragment(); fragment.setArguments(bundle); FragmentManager fragmentManager = ((FragmentActivity) context).getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.frame_id, fragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit();
You can pass data activity to fragment via Bundle Bundle bundle = new Bundle(); bundle.putString("edttext", "From Activity"); // set Fragmentclass Arguments Fragmentclass fragobj = new Fragmentclass(); fragobj.setArguments(bundle); To get those datas in fragment String strtext = getArguments().getString("edttext"); return inflater.inflate(R.layout.fragment, container, false);
Supported Locales - ga_IE
while setting locale for google sheet api, throws the followinge error Invalid requests[0].updateSpreadsheetProperties: Unsupported locale: ga_IE", "status" : "INVALID_ARGUMENT" Reviewing the API doc, it seems to be not all locales are supported. The locale of the spreadsheet in one of the following formats: an ISO 639-1 language code such as en an ISO 639-2 language code such as fil, if no 639-1 code exists a combination of the ISO language code and country code, such as en_US Note: when updating this field, not all locales/languages are supported. Where can I find the list of supported locale?
As you quotes over Spreadsheet Properties, ISO 639-1 codes are preferred in first instance, ISO 639-2 are used when no ISO 639-1 exists, and, if no code exists for a given language on those ISOs, the combination of language_COUNTRY is used. This later case varies depending on the context. I assume that your code lays in any of the ISOs 639-1/2, so here you have the full lists: ISO 639-1 Language 639-1 code Abkhazian ab Afar aa Afrikaans af Akan ak Albanian sq Amharic am Arabic ar Aragonese an Armenian hy Assamese as Avaric av Avestan ae Aymara ay Azerbaijani az Bambara bm Bashkir ba Basque eu Belarusian be Bengali bn Bihari languages bh Bislama bi Bosnian bs Breton br Bulgarian bg Burmese my Catalan, Valencian ca Chamorro ch Chechen ce Chichewa, Chewa, Nyanja ny Chinese zh Chuvash cv Cornish kw Corsican co Cree cr Croatian hr Czech cs Danish da Divehi, Dhivehi, Maldivian dv Dutch, Flemish nl Dzongkha dz English en Esperanto eo Estonian et Ewe ee Faroese fo Fijian fj Finnish fi French fr Fulah ff Galician gl Georgian ka German de Greek, Modern (1453-) el Guarani gn Gujarati gu Haitian, Haitian Creole ht Hausa ha Hebrew he Herero hz Hindi hi Hiri Motu ho Hungarian hu Interlingua(International Auxiliary Language Association) ia Indonesian id Interlingue, Occidental ie Irish ga Igbo ig Inupiaq ik Ido io Icelandic is Italian it Inuktitut iu Japanese ja Javanese jv Kalaallisut, Greenlandic kl Kannada kn Kanuri kr Kashmiri ks Kazakh kk Central Khmer km Kikuyu, Gikuyu ki Kinyarwanda rw Kirghiz, Kyrgyz ky Komi kv Kongo kg Korean ko Kurdish ku Kuanyama, Kwanyama kj Latin la Luxembourgish, Letzeburgesch lb Ganda lg Limburgan, Limburger, Limburgish li Lingala ln Lao lo Lithuanian lt Luba-Katanga lu Latvian lv Manx gv Macedonian mk Malagasy mg Malay ms Malayalam ml Maltese mt Maori mi Marathi mr Marshallese mh Mongolian mn Nauru na Navajo, Navaho nv North Ndebele nd Nepali ne Ndonga ng Norwegian Bokmål nb Norwegian Nynorsk nn Norwegian no Sichuan Yi, Nuosu ii South Ndebele nr Occitan oc Ojibwa oj Church Slavic, Old Slavonic, Church Slavonic, Old Bulgarian,Old Church Slavonic cu Oromo om Oriya or Ossetian, Ossetic os Punjabi, Panjabi pa Pali pi Persian fa Polish pl Pashto, Pushto ps Portuguese pt Quechua qu Romansh rm Rundi rn Romanian, Moldavian, Moldovan ro Russian ru Sanskrit sa Sardinian sc Sindhi sd Northern Sami se Samoan sm Sango sg Serbian sr Gaelic, Scottish Gaelic gd Shona sn Sinhala, Sinhalese si Slovak sk Slovenian sl Somali so Southern Sotho st Spanish, Castilian es Sundanese su Swahili sw Swati ss Swedish sv Tamil ta Telugu te Tajik tg Thai th Tigrinya ti Tibetan bo Turkmen tk Tagalog tl Tswana tn Tonga(Tonga Islands) to Turkish tr Tsonga ts Tatar tt Twi tw Tahitian ty Uighur, Uyghur ug Ukrainian uk Urdu ur Uzbek uz Venda ve Vietnamese vi Volapük vo Walloon wa Welsh cy Wolof wo Western Frisian fy Xhosa xh Yiddish yi Yoruba yo Zhuang, Chuang za Zulu zu ISO 639-2 not covered by ISO 639-1 Language ISO 639-2 Achinese ace Acoli ach Adangme ada Adyghe; Adygei ady Afro-Asiatic languages afa Afrihili afh Ainu ain Akkadian akk Aleut ale Algonquian languages alg Southern Altai alt English, Old(ca.450–1100) ang Angika anp Apache languages apa Official Aramaic(700–300 BCE);Imperial Aramaic(700–300 BCE) arc Mapudungun;Mapuche arn Arapaho arp Artificial languages art Arawak arw Asturian;Bable;Leonese;Asturleonese ast Athapascan languages ath Australian languages aus Awadhi awa Banda languages bad Bamileke languages bai Baluchi bal Balinese ban Basa bas Baltic languages bat Beja;Bedawiyet bej Bemba bem Berber languages ber Bhojpuri bho Bikol bik Bini;Edo bin Siksika bla Bantu (Other) bnt Braj bra Batak languages btk Buriat bua Buginese bug Blin; Bilin byn Caddo cad Central American Indian languages cai Galibi Carib car Caucasian languages cau Cebuano ceb Celtic languages cel Chibcha chb Chagatai chg Chuukese chk Mari chm Chinook jargon chn Choctaw cho Chipewyan;Dene Suline chp Cherokee chr Cheyenne chy Chamic languages cmc Montenegrin cnr Coptic cop Creolesandpidgins, English based cpe Creolesand pidgins, French-based cpf Creolesand pidgins, Portuguese-based cpp Crimean Tatar;Crimean Turkish crh Creolesandpidgins crp Kashubian csb Cushitic languages cus Dakota dak Dargwa dar Land Dayak languages day Delaware del Slave (Athapascan) den Dogrib dgr Dinka din Dogri doi Dravidian languages dra Lower Sorbian dsb Duala dua Dutch, Middle(ca. 1050–1350) dum Dyula dyu Efik efi Egyptian (Ancient) egy Ekajuk eka Elamite elx English, Middle(1100–1500) enm Ewondo ewo Fang fan Fanti fat Filipino;Pilipino fil Finno-Ugrian languages fiu Fon fon French, Middle(ca. 1400–1600) frm French, Old(842–ca. 1400) fro Northern Frisian frr Eastern Frisian frs Friulian fur Ga gaa Gayo gay Gbaya gba Germanic languages gem Geez gez Gilbertese gil German, Middle High(ca. 1050–1500) gmh German, Old High(ca. 750–1050) goh Gondi gon Gorontalo gor Gothic got Grebo grb Greek, Ancient(to 1453) grc Swiss German;Alemannic;Alsatian gsw Gwich'in gwi Haida hai Hawaiian haw Hiligaynon hil Himachali languages; Pahari languages him Hittite hit Hmong;Mong hmn Upper Sorbian hsb Hupa hup Iban iba Ijo languages ijo Iloko ilo Indic languages inc Indo-European languages ine Ingush inh Iranian languages ira Iroquoian languages iro Lojban jbo Judeo-Persian jpr Judeo-Arabic jrb Kara-Kalpak kaa Kabyle kab Kachin;Jingpho kac Kamba kam Karen languages kar Kawi kaw Kabardian kbd Khasi kha Khoisan languages khi Khotanese;Sakan kho Kimbundu kmb Konkani kok Kosraean kos Kpelle kpe Karachay-Balkar krc Karelian krl Kru languages kro Kurukh kru Kumyk kum Kutenai kut Ladino lad Lahnda lah Lamba lam Lezghian lez Mongo lol Lozi loz Luba-Lulua lua Luiseno lui Lunda lun Luo (Kenya and Tanzania) luo Lushai lus Madurese mad Magahi mag Maithili mai Makasar mak Mandingo man Austronesian languages map Masai mas Moksha mdf Mandar mdr Mende men Irish, Middle(900–1200) mga Mi'kmaq;Micmac mic Minangkabau min Uncoded languages mis Mon-Khmer languages mkh Manchu mnc Manipuri mni Manobo languages mno Mohawk moh Mossi mos Multiple languages mul Munda languages mun Creek mus Mirandese mwl Marwari mwr Mayan languages myn Erzya myv Nahuatl languages nah North American Indian languages nai Neapolitan nap Low German; Low Saxon; German, Low; Saxon, Low nds Nepal Bhasa;Newari new Nias nia Niger-Kordofanian languages nic Niuean niu Nogai nog Norse, Old non N'Ko nqo Pedi;Sepedi;Northern Sotho nso Nubian languages nub Classical Newari;Old Newari;Classical Nepal Bhasa nwc Nyamwezi nym Nyankole nyn Nyoro nyo Nzima nzi Osage osa Turkish, Ottoman(1500–1928) ota Otomian languages oto Papuan languages paa Pangasinan pag Pahlavi pal Pampanga;Kapampangan pam Papiamento pap Palauan pau Persian, Old(ca. 600–400 B.C.) peo Philippine languages phi Phoenician phn Pohnpeian pon Prakrit languages pra Provençal, Old(to 1500);Old Occitan (to 1500) pro Reserved for local use qaa-qtz Rajasthani raj Rapanui rap Rarotongan;Cook Islands Maori rar Romance languages roa Romany rom Aromanian;Arumanian;Macedo-Romanian rup Sandawe sad Yakut sah South American Indian (Other) sai Salishan languages sal Samaritan Aramaic sam Sasak sas Santali sat Sicilian scn Scots sco Selkup sel Semitic languages sem Irish, Old(to 900) sga Sign Languages sgn Shan shn Sidamo sid Siouan languages sio Sino-Tibetan languages sit Slavic languages sla Southern Sami sma Sami languages smi Lule Sami smj Inari Sami smn Skolt Sami sms Soninke snk Sogdian sog Songhai languages son Sranan Tongo srn Serer srr Nilo-Saharan languages ssa Sukuma suk Susu sus Sumerian sux Classical Syriac syc Syriac syr Tai languages tai Timne tem Tereno ter Tetum tet Tigre tig Tiv tiv Tokelau tkl Klingon;tlhIngan-Hol tlh Tlingit tli Tamashek tmh Tonga (Nyasa) tog Tok Pisin tpi Tsimshian tsi Tumbuka tum Tupi languages tup Altaic languages tut Tuvalu tvl Tuvinian tyv Udmurt udm Ugaritic uga Umbundu umb Undetermined und Vai vai Votic vot Wakashan languages wak Walamo wal Waray war Washo was Sorbian languages wen Kalmyk;Oirat xal Yao yao Yapese yap Yupik languages ypk Zapotec zap Blissymbols;Blissymbolics;Bliss zbl Zenaga zen Standard Moroccan Tamazight zgh Zande languages znd Zuni zun No linguistic content; Not applicable zxx Zaza;Dimili;Dimli;Kirdki;Kirmanjki;Zazaki zza Just for clarification: you can see the full list of ISO 639 codes on the Library of Congress. As I said before, I assume that your language is one of the former. If that is not the case, please ask for further help so I can assist you better.
Listing db elements
I am getting some data from a db.For all data found in first table is compared with data from second table.So I am retrieving ingredients stored in one table and those ingredients are compared with users favorite ingredients stored in second table. I want for each row that contains ingredients to list if there are the same ingredients as favorite ingredients. Now I retrieve all data from db and the comparison is made for all ingredients, not for each one independently. Here is my code: Statement st1 = con.createStatement(); rs1 = st1.executeQuery("Select Nume from ingredientplacut where Id_user = '24'"); while( rs1.next()) { String nrRet1 = rs1.getString("Nume"); secondList.add(nrRet1); } System.out.println(secondList); Statement st = con.createStatement(); java.sql.PreparedStatement ps=con.prepareStatement("SELECT ID_reteta,Nume,Descriere,Ingrediente,Mod_preparare,Dificultate,Tip,Imagini,Total_grasimi,Total_carbohidrati,Total_proteine,Total_calorii FROM reteta"); rs=ps.executeQuery(); while( rs.next()){ String nrRet = rs.getString("Ingrediente"); firstList.add(nrRet); System.out.println("----"); } ArrayList<String> al3= new ArrayList<String>(); for (String temp : firstList) { boolean isTrue=false; for(String temp2:secondList) { if(temp.contains(temp2)) { isTrue=true; break; } } if(isTrue) al3.add("YES"); else al3.add("NO"); } System.out.println(al3); System.out.println(firstList); ArrayList<Integer> al4= new ArrayList<Integer>(); for (String temp2 : secondList) { boolean isTrue = false; for (String temp : firstList) { if (temp.contains(temp2)) { isTrue = true; break; } } if (isTrue) al4.add(1); else al4.add(0); } System.out.println(al4); And the output is: [afine, almette, alune, albus de ou de gaina, andive, mere] ---- ---- [YES, YES, NO, NO, NO, NO, NO, NO, YES] [200 grame fusilli cu legume (afine,alune); 200 grame smantana 12%; 50 grame iaurt; 50 grame cascaval afumat ; 1/2 lingurite mustar; doi catei de usturoi sau o lingurita de usturoi deshidratat; mere; patrunjel; piper; sare., 250 grame dovleac ras; 170 grame fulgi fini de ovaz; 150 ml lapte dulce; 80 grame stafide; un ou; doua linguri faina integrala; 40 grame miere; un plic de zahar vanilat; ½ lingurita scortisoara; afine; putina sare., 4 medalioane de somon proaspat (aproximativ 800 grame); un ardei rosu mare; o lamaie mica; o rosie medie; putin patrunjel; 4-5 catei de usturoi; doua lingurite capere; 2-3 linguri ulei de masline; piper; boia dulc; sare., 150 grame maioneza de casa; 300 grame telina (net); 300 grame piept sau pulpe dezosate; 1/3 capatani usturoi; marar si patrunjel dupa gust; aprox 1/2 borcan castraveti murati in otet; o lingura boia dulce; ½ lingurite piper; 10-20 ml ulei masline. [1, 0, 1, 0, 0, 1] And I want the output be : [200 grame fusilli cu legume (afine,alune); 200 grame smantana 12%; 50 grame iaurt; 50 grame cascaval afumat ; 1/2 lingurite mustar; doi catei de usturoi sau o lingurita de usturoi deshidratat; mere; patrunjel; piper; sare. [1, 0, 1, 0, 0, 1] //3 ingredients related 250 grame dovleac ras; 170 grame fulgi fini de ovaz; 150 ml lapte dulce; 80 grame stafide; un ou; doua linguri faina integrala; 40 grame miere; un plic de zahar vanilat; ½ lingurita scortisoara; afine; putina sare., [0, 0, 0, 1, 0, 0] //one ingredient related 4 medalioane de somon proaspat (aproximativ 800 grame); un ardei rosu mare; o lamaie mica; o rosie medie; putin patrunjel; 4-5 catei de usturoi; doua lingurite capere; 2-3 linguri ulei de masline; piper; boia dulc; sare. [0, 0, 0, 0, 0, 0] //0 Ingredients related 150 grame maioneza de casa; 300 grame telina (net); 300 grame piept sau pulpe dezosate; 1/3 capatani usturoi; marar si patrunjel dupa gust; aprox 1/2 borcan castraveti murati in otet; o lingura boia dulce; ½ lingurite piper; 10-20 ml ulei masline. [0, 0, 0, 0, 0, 0] //0 Ingredients related Could anyone help me?
I am not 100% sure, if I get all the aspects fully right and my Romanian also is very bad, but here's what I got: We have table called ingredientplacut which apparently list all ingredients, which the users like. We may assume that the name of the ingredient is stored in attribute name there, that the identifier of the user we are looking for is known that the attribute user_id of ingredientplacut provides the identifier of the user and thus is part of the primary key in this table. The table reteta apparently provides the ingredients for a given recipe and appears to be denormalized (#Bogdan: if this isn't already a view on another DB tables, kindly check your relational data model. Otherwise, you highly risk to run into delete and update anormalies). The name of the ingredient there is stored in attribute Ingrediente. The list of ingredients of the recipes can then be easily checked, if they are "favorite ingredients" by issuing the following join: SELECT r.ID_reteta, r.Ingrediente, fav.name IS NOT NULL as isFavorite FROM retata as r LEFT JOIN inredientplacut as fav ON r.Ingrediente = fav.name WHERE fav.user_id = '24' Given this statement, it is also easy to determine the recipe with the "most liked" ingredients: SELECT ID_retata, count(*) as favoriteIngredients FROM ( SELECT r.ID_reteta, r.Ingrediente, fav.name IS NOT NULL as isFavorite FROM retata as r LEFT JOIN inredientplacut as fav ON r.Ingrediente = fav.name WHERE fav.user_id = '24' ) as favlist WHERE favlist.isFavorite = true ORDER BY favoriteIngredients DESC GROUP BY ID_retata Please note, however, that this is a very bad performance indicator, as there is no weighting considered for the ingredients (I may like pepper and onions, but this doesn't mean that I like all the dishes where both of them is in...) For sure, you may implement such a LEFT JOIN also on PHP level by reading only the source tables via SQL. However, I would try to avoid this due to multiple reasons: The DB optimizer is virtually not able to help you, so you need to be "better than the optimizer" - which I doubt that a interpreter-based language like PHP can be. You need to retrieve all the recipes (which might become a huge table) from the DB into PHP. So, your calculation is transferred through multiple stacks, the data types need to be verified and so forth. In short, your processing is "farer away" from the data - this is known to be slower by architecture. The coding is much worse to read and thus even worse to maintain. The SQL statement might not be too easy as well as it is more abstract, but by its descriptive nature, your intentions are visible in a more compact manner. (NB: A seldom case, where more abstraction provides better performance - usually, mixing those two architectural concepts doesn't work out that well).
Error While Getting Response from SOAP Webservice [duplicate]
This question already has answers here: Not Getting Correct Response of SOAP Web service Programatically (2 answers) Closed 10 years ago. For Getting the Response from SOAP Webservice i have do the Following as Needed. SOAPUI Request : <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test.login/"> <soapenv:Header/> <soapenv:Body> <test:Login> <!--Optional:--> <arg0>best_buyer_editor</arg0> <!--Optional:--> <arg1>welcome</arg1> <!--Optional:--> <arg2>Mobile</arg2> </test:Login> </soapenv:Body> </soapenv:Envelope> SOAPUI Response : <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns2:LoginResponse xmlns:ns2="http://test.login/"> <return>{"LoginDetails":{"Result":"Success","UserName":"Best Buyer Editor","token":"M7M5RMQU6","rolelist":["buyer_editor","admin_role"],"parties":[{"partynumber":"BEST","type":"self","sites":[{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-1","siteaddress":"225 E Industrial Blvd Waco USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-5","siteaddress":"20 Milburn St Buffalo USA"},{"companyname":"Best Engineers Manufacturing USA Inc","sitecode":"BESTHQ","siteaddress":"8976, Hope vision Lane Simple City USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-6","siteaddress":"Cedar & Ellicott Sts Batavia USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-2","siteaddress":"9700 Richmond Ave Ste 201 Houston USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-4","siteaddress":"3315 Ashlock Dr Houston USA"},{"companyname":"Best Engineers Manufacturing USA Inc","sitecode":"BESTWH","siteaddress":"1021, Industrial Bolevar San Macros City USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYMEX-10","siteaddress":"271 Madison Ave Ste 1003 New York USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-8","siteaddress":"271 Madison Ave Ste 1003 New York USA"},{"companyname":"Best Engineers Manufacturing Europe Inc","sitecode":"BESTMO","siteaddress":"789,Future Vision Towers London GBR"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-7","siteaddress":"1580 Columbia Tpke Ste 5 Castleton On Hudson USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYMEX-9","siteaddress":"271 Madison Ave Ste 1003 New York USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-3","siteaddress":"2821 Lackland Rd Ste 340 Fort Worth USA"}]},{"partynumber":"DHL","type":"sponsors","sites":[{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-2","siteaddress":"11311 N Central Expy Dallas USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-7","siteaddress":"150 W 22nd St Fl 5 New York USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYMEX-9","siteaddress":"One Markin Lane Wyoming USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-6","siteaddress":"12685 State Route 38 Berkshire USA"},{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-4","siteaddress":"2221 Canada Dry St Houston USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-5","siteaddress":"521 5th Ave Rm 2130 New York USA"},{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-1","siteaddress":"6505 N Houston Rosslyn Rd Houston USA"},{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-3","siteaddress":"9405 N County Road 2000 Lubbock USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYMEX-10","siteaddress":"One Markin Lane Wyoming USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-8","siteaddress":"One Markin Lane Wyoming USA"}]},{"partynumber":"UPS","type":"sponsors","sites":[{"companyname":"www.ups.com","sitecode":"UPSTXUSA-3","siteaddress":"1455 West Loop S Houston USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-8","siteaddress":"1050 Hook Rd Farmington USA"},{"companyname":"www.ups.com","sitecode":"UPSNYMEX-10","siteaddress":"1050 Hook Rd Farmington USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-7","siteaddress":"1400 Broadway Fl 2 New York USA"},{"companyname":"www.ups.com","sitecode":"UPSTXUSA-4","siteaddress":"14902 Sommermeyer St Ste 100 Houston USA"},{"companyname":"www.ups.com","sitecode":"UPSNYMEX-9","siteaddress":"1050 Hook Rd Farmington USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-6","siteaddress":"101 Cranbrook Ext Tonawanda USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-5","siteaddress":"290 Barrett Hill Rd Mahopac USA"},{"companyname":"www.ups.com","sitecode":"UPSTXUSA-2","siteaddress":"11308 Midmorning Dr Austin USA"},{"companyname":"www.ups.com","sitecode":"UPSTXUSA-1","siteaddress":"3900 Harrisburg Blvd Houston USA"}]},{"partynumber":"HDEPO","type":"sponsors","sites":[{"companyname":"Home Depot USA.","sitecode":"HDEPOWH","siteaddress":"55031 Hdepo WH Road Bossier City USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-8","siteaddress":"166 Haverford Rd Hicksville USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-4","siteaddress":"4901 Blaffer St Houston USA"},{"companyname":"Home Depot USA.","sitecode":"HDEPOHQ","siteaddress":"5031 Hdepo HQ Road Bossier City USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYMEX-9","siteaddress":"166 Haverford Rd Hicksville USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-6","siteaddress":"1790 Broadway Ste 702 New York USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-3","siteaddress":"2203 Timberloch Pl Ste 252 The Woodlands USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYMEX-10","siteaddress":"166 Haverford Rd Hicksville USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-5","siteaddress":"1040 Avenue Of The Americas New York USA"},{"companyname":"Home Depot USA.","sitecode":"HDEPOMO","siteaddress":"5031 Hdepo MO Road Bossier City USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-1","siteaddress":"14603 Chrisman Rd Houston USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-2","siteaddress":"16103 University Oak San Antonio USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-7","siteaddress":"392 Pulteney St Corning USA"}]},{"partynumber":"GWILL","type":"sponsors","sites":[{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYMEX-9","siteaddress":"3300 Northern Blvd Fl 2 Long Island City USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLHQ","siteaddress":"543, Light Ray Street Wellknown city In"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYMEX-10","siteaddress":"3300 Northern Blvd Fl 2 Long Island City USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-7","siteaddress":"1800 New Hwy Farmingdale USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-8","siteaddress":"3300 Northern Blvd Fl 2 Long Island City USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLMO","siteaddress":"6789, Engineering Laner Large city GBR"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-2","siteaddress":"945 McKinney St # 237 Houston USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-6","siteaddress":"580 Broadway Menands USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-3","siteaddress":"6921 Olson Ln Pasadena USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-1","siteaddress":"7075 Ranch Road 2338 Georgetown USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-4","siteaddress":"3839 Dilido Rd Dallas USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-5","siteaddress":"1 Radisson Plz Ste 803 New Rochelle USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLHQ","siteaddress":"543, Light Ray Street Wellknown city USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLWH","siteaddress":"2345, Well formed lane Hope in city USA"}]},{"partynumber":"FEDEX","type":"sponsors","sites":[{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-2","siteaddress":"400 Langford St Clint USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-8","siteaddress":"3736 Kellogg Rd Cortland USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-4","siteaddress":"5025 East Business 20 Abilene USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-5","siteaddress":"637 New Loudon Rd Ste 2 Latham USA"},{"companyname":"Fedex USA.","sitecode":"FEDEXWH","siteaddress":"6754 Fedex WH Road Fedex City USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-1","siteaddress":"4305 N Interstate 35 Denton USA"},{"companyname":"Fedex USA.","sitecode":"FEDEXHQ","siteaddress":"7800 Fedex HQ Road Bossier City USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-3","siteaddress":"14444 Stuebner Airline Rd Houston USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYMEX-10","siteaddress":"3736 Kellogg Rd Cortland USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-7","siteaddress":"65 Old Indian Rd Milton USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYMEX-9","siteaddress":"3736 Kellogg Rd Cortland USA"},{"companyname":"Fedex USA.","sitecode":"FEDEXMO","siteaddress":"9600 Fedex MO Road Bossier City USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-6","siteaddress":"1254 Erie Ave North Tonawanda USA"}]}]}}</return> </ns2:LoginResponse> </soap:Body> </soap:Envelope> MY Code : URL = "http://test.tpsynergy.com:8080/tpsynergy/services/login"; SOAP_ACTION = "http://test.tpsynergy.com:8080/tpsynergy/services/login"; METHOD = "Login"; NAMESPACE = "http://test.login/"; SoapObject request = new SoapObject(NAMESPACE, "Login"); request.addProperty("arg0", "best_buyer_editor"); request.addProperty("arg1", "welcome"); request.addProperty("arg2", "Mobile"); Log.i(TAG, "Request for getting airport list" + request.toString()); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); envelope.dotNet = true; HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); if (envelope.bodyIn instanceof SoapFault) { String str= ((SoapFault) envelope.bodyIn).faultstring; Log.i("", str); } else { SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; response = resultsRequestSOAP.getProperty(0).toString(); Log.i(" Login Webservice Response", "Responce ---->" + (resultsRequestSOAP.getProperty(0).toString())); } } catch (Exception e) { Log.i(TAG, "Exception e" + e.toString()); } After Executing the above code i am getting Following Error: Unmarshalling Error: unexpected element (uri:"http://test.login/", local:"arg0"). Expected elements are <{}arg2>,<{}arg1>,<{}arg0> Can Anyone Tell me why i am getting Success in SOAPUI bt not through my code. I have referred many SO link but not able to solve my Problem. What My Question : I really Do not understand Know what the Error is Trying to say by Expected elements are <{}arg2>,<{}arg1>,<{}arg0>. What is the Solution to Get out of this Problem? Thanks in Advance.
Use TCP monitor to check what is the SOAP request that is sent. I suspect based on error message, the elements arg* are qualified with the namespace where as the webservice does not expect them that way. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test.login/"> <soapenv:Header/> <soapenv:Body> <test:Login> <!--Optional:--> <test:arg0>best_buyer_editor</test:arg0> <!--Optional:--> <test:arg1>welcome</test:arg1> <!--Optional:--> <test:arg2>Mobile</test:arg2> </test:Login> </soapenv:Body> </soapenv:Envelope>