Displaying Data in a Table Android Development? - java

Working on my first app for android and want to display some data in a table(or something similar). After looking around here I guess android does not support something like a JTable; someone said you have to create a custom table? What is the best way to display data that is a string in CSV format? In a Java app I created I have a function that creates a 2D Array out of the string and throws that into a JTable.
Data Format in String:
Sun 02-16-14 09:45 PM,1,REAL TIRED,JUST WACK AT IT,2 - 4,
Sun 02-23-14 08:10 PM,1,BALLERS,REAL TIRED,4 - 11,
Sun 03-02-14 09:00 PM,1,REAL TIRED,EL TRI,1 - 7,
Sun 03-09-14 05:50 PM,1,GO GO POWER RANGERS,REAL TIRED,4 - 9,
Sun 03-16-14 06:40 PM,1,REAL TIRED,GAME OF GROANS,16 - 0,
Sun 03-23-14 09:00 PM,1,HUNGOVER HAT TRICKS,REAL TIRED,
Sun 03-30-14 07:25 PM,1,REAL TIRED,PRESTIGE WORLD WIDE,
Sun 04-06-14 04:20 PM,1,REAL TIRED,BALLERS,
Not sure if there are any good options because of the limited space for mobile devices. Maybe only display one row at a time and be able to click through them?

You can try this example, you will be very comfortable with this code. Even though if you want to add rows in the table view dynamically from an server or from an API call then just create a for loop and add it according this example.
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
String[] presidents = { "Dwight D. Eisenhower", "John F. Kennedy",
"Lyndon B. Johnson", "Richard Nixon", "Gerald Ford",
"Jimmy Carter", "Ronald Reagan", "George H. W. Bush",
"Bill Clinton", "George W. Bush", "Barack Obama",
"Dwight D. Eisenhower", "John F. Kennedy", "Lyndon B. Johnson",
"Richard Nixon", "Gerald Ford", "Jimmy Carter",
"Ronald Reagan", "George H. W. Bush", "Bill Clinton",
"George W. Bush", "Barack Obama", "Dwight D. Eisenhower",
"John F. Kennedy", "Lyndon B. Johnson", "Richard Nixon",
"Gerald Ford", "Jimmy Carter", "Ronald Reagan",
"George H. W. Bush", "Bill Clinton", "George W. Bush",
"Barack Obama" };
ScrollView scrollView = new ScrollView(this);
TableLayout tableLayout = new TableLayout(this);
for (int i = 0; i < presidents.length; i++) {
TableRow tableRow = new TableRow(this);
TextView tv = new TextView(this);
tv.setPadding(10, 10, 10, 10);
tv.setGravity(Gravity.CENTER);
tv.setText(presidents[i]);
tableRow.addView(tv);
tableLayout.addView(tableRow);
View v = new View(this);
v.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT, 1));
v.setBackgroundColor(Color.rgb(51, 51, 51));
tableLayout.addView(v);
}
scrollView.addView(tableLayout);
setContentView(scrollView);
}
}
Hope so you would like this. If this is suitable to you then please mark as accepted answer so that it could be helpful for others.

Related

What is the way to get a list of options that can be selected from a dropdown using Selenium and Java?

I want to get a list of all the options that can be selected from a dropdown menu in selenium using java. How can I do that?
Use this method
getAllSelectedOptions()
Refer this site for more information
https://www.codota.com/code/java/methods/org.openqa.selenium.support.ui.Select/getAllSelectedOptions
There are multiple approaches to print the texts from the option elements of a drop-down-menu. Ideally while interacting with a html-selct you need to use the Select Class. Further to interact with all the <option> tags you need to use getOptions() method. As an example to print the texts from the Day, Month and Year option elements within facebook landing page https://www.facebook.com/ you you need to use WebDriverWait for the elementToBeClickable() and you can use the following Locator Strategies.
Options from Day Dropdown using id attribute:
WebElement dayElement = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("day")));
Select selectDay = new Select(dayElement);
List<WebElement> dayList = selectDay.getOptions();
for (int i=0; i<dayList.size(); i++)
System.out.println(dayList.get(i).getText());
Options from Month Dropdown using xpath and java-8 stream() and map():
Select selectMonth = new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//select[#id='month']"))));
List<String> myMonths = selectMonth.getOptions().stream().map(element->element.getText()).collect(Collectors.toList());
System.out.println(myMonths);
Console Output:
[Month, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sept, Oct, Nov, Dec]
Options from Month Dropdown using [tag:css_selectors] and java-8 stream() and map() in a single line of code:
System.out.println(new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("select#year")))).getOptions().stream().map(element->element.getText()).collect(Collectors.toList()));
Console Output:
[Year, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009, 2008, 2007, 2006, 2005, 2004, 2003, 2002, 2001, 2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981, 1980, 1979, 1978, 1977, 1976, 1975, 1974, 1973, 1972, 1971, 1970, 1969, 1968, 1967, 1966, 1965, 1964, 1963, 1962, 1961, 1960, 1959, 1958, 1957, 1956, 1955, 1954, 1953, 1952, 1951, 1950, 1949, 1948, 1947, 1946, 1945, 1944, 1943, 1942, 1941, 1940, 1939, 1938, 1937, 1936, 1935, 1934, 1933, 1932, 1931, 1930, 1929, 1928, 1927, 1926, 1925, 1924, 1923, 1922, 1921, 1920, 1919, 1918, 1917, 1916, 1915, 1914, 1913, 1912, 1911, 1910, 1909, 1908, 1907, 1906, 1905]
This approch might help you to get understand how to get all selectable options from dropdown
driver.navigate().to("https://the-internet.herokuapp.com/");
WebDriverWait wait = new WebDriverWait(driver,10,100);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#href='/dropdown']"))).click();
WebElement element = driver.findElement(By.xpath("//select[#id='dropdown']"));
Select select = new Select(element);
List<WebElement>allOptions = select.getOptions();
allOptions.forEach(value->{System.out.println(value.getText());});

Gregorian Calendar JavaFX

I am stuck trying to figure out this question. It is about JavaFX control choosing the name of the day for the month, number day and year when pressing enter.. I even tried using object oriented to solve the problem. The question is in a picture link. Here is the question in this link.
New EDIT and Code: I am off by one day for getting the day of the week for example January 1, 2012 should be day 1 as the answer in console: Day of Week: 1 not 2.
public class DayOfWeek extends Application {
private String[] months = { "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER",
"OCTOBER", "NOVEMBER", "DECEMBER" };
private String[] days = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" };
String s1 = "";
int k = 0;
String s2 = "";
int x = 0;
#Override
public void start(Stage primaryStage) {
// add a gridpane
GridPane grid = new GridPane();
grid.setPadding(new Insets(10, 10, 10, 10));
// add a label for original message top left side
Label label1 = new Label("Month: ");
GridPane.setConstraints(label1, 0, 0);
ListView<String> lv = new ListView<>(FXCollections.observableArrayList(months));
lv.setPrefSize(100, 100);
lv.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
GridPane.setConstraints(lv, 1, 0);
Label label2 = new Label("Day: ");
GridPane.setConstraints(label2, 2, 0);
ListView<String> lvdays = new ListView<>(FXCollections.observableArrayList(days));
lvdays.setPrefWidth(50);
lvdays.setPrefHeight(75);
lv.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
GridPane.setConstraints(lvdays, 3, 0);
Label label3 = new Label("Year: ");
GridPane.setConstraints(label3, 4, 0);
TextField textfield3 = new TextField();
GridPane.setConstraints(textfield3, 5, 0);
lv.setOnMouseClicked(e -> {
s1 = lv.getSelectionModel().getSelectedItem();
k = lv.getSelectionModel().getSelectedIndex();
System.out.println(lv.getSelectionModel().getSelectedItem());
});
lvdays.setOnMouseClicked(e2 -> {
s2 = lvdays.getSelectionModel().getSelectedItem();
x = lvdays.getSelectionModel().getSelectedIndex();
System.out.println(lvdays.getSelectionModel().getSelectedItem());
});
textfield3.setOnKeyPressed(e3 -> {
if (e3.getCode() == KeyCode.ENTER) {
GregorianCalendar cal2 = new GregorianCalendar(textfield3.getLength(), k, x);
System.out.println("Day of Week: " + cal2.get(Calendar.DAY_OF_WEEK));
}
});
// add it to the parent
grid.getChildren().addAll(label1, lv, label2, lvdays, label3, textfield3);
// set a scene and place show it
Scene scene = new Scene(grid, 600, 200);
primaryStage.setTitle("Day of Week");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
First, don’t fill strings into your list views. Fill the month list view from Month.values() and the days of the month with Integer objects. This will be more convenient when taking the selected item out and will save you of declaring the arrays at the top of the class.
In the following I am assuming that instead of s1 you have a variable named m of type Month for the month and s2 has type Integer (you should find a better name).
String yearText = textfield3.getText();
try {
int year = Integer.parseInt(yearText);
LocalDate date = LocalDate.of(year, m, s2);
System.out.println("Day of Week: " + date.getDayOfWeek());
} catch (NullPointerException | NumberFormatException | DateTimeException e) {
System.out.format("Not a valid date: %s %s %d", yearText, m, s2);
}
Avoid using GregorianCalendar. That class was poorly designed and is fortunately long outdated. Instead use LocalDate from java.time, the modern Java date and time API.
Opposite the GregorianCalendar constructor the LocalDate.of method will throw an exception if you pass invalid values to it, such as for example 29 of February 2019. This will help you report the invalid date to the user as required.
What went wrong in your code?
You were using textfield3.getLength() for the year. Assuming a four digit year was entered this would give you year 4 (that’s a couple of millennia ago now).
When you used lvdays.getSelectionModel().getSelectedIndex() for the day of month, you got the 0-based index in the list in the list view. So when the user picked 1 you were getting 0, etc.
Other tip: Learn to invent good variable names. It really makes the difference between valuable and worthless code. Also when asking a question on Stack Overflow, people will be more likely to help you if they can read your code easily, which they cannot with the variable names s1, s2, k and x.
Link
Oracle tutorial: Date Time explaining how to use java.time.

JSON Parsing Error: Unexpected character (s) at position 226025

I saw similar question on Stackoverflow but none of them helped me to solve my issue. So, I am asking for help as I have tried to find out what is the reason behind the error I am getting but failed. Please don't mark it as a duplicate question.
I am parsing a Json file and getting the following error.
Jun 06, 2017 2:06:24 PM edu.virginia.cs.services.FileManager ParseJson
SEVERE: null
Unexpected character (s) at position 226025.
at org.json.simple.parser.Yylex.yylex(Yylex.java:610)
at org.json.simple.parser.JSONParser.nextToken(JSONParser.java:269)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:118)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:92)
at edu.virginia.cs.services.FileManager.ParseJson(FileManager.java:68)
at edu.virginia.cs.main.Processer.main(Processer.java:20)
Exception in thread "main" java.lang.NullPointerException
at edu.virginia.cs.services.FileManager.ParseJson(FileManager.java:76)
at edu.virginia.cs.main.Processer.main(Processer.java:20)
Code of interest:
try {
arr = (JSONArray) parser.parse(new FileReader(sourceFile));
} catch (IOException | ParseException ex) {
Logger.getLogger(FileManager.class.getName()).log(Level.SEVERE, null, ex);
}
File content looks like as follows:
[
{
"url": "http://www.save-on-crafts.com/",
"title": "Events & Wedding Sale | Save 20-60% | SaveOnCrafts",
"content": {
"p": ["Wedding decorations, party supplies, home d cor & craft supplies at 20-70% off. Save On Crafts brings you classic and trending fashions.", "Save On Crafts has continually evolved to meet the needs of our customers DIY brides, home decorators, party planners, florists, and caterers. Our goal is simple: provide an exciting selection of quality , , and items at the lowest price possible for the customer with discerning taste."],
"div": ["indicates required", "(831) 768-8428", "Take a Peek at our Specials: Save up to 70%!", "Candle Holders", "Flowers & Branches", "Crystal D cor, Chandeliers", "Set the Mood with Candles", "Champagne & Ice Buckets", "Chalkboards", "Eco Confetti", "Wedding Signs", "Sola Flowers", "Natural Wood Slices", "Classic & trending styles without the traditional retail markup.", "(831) 768-8428"],
"a": ["X", "What's New", "SPECIALS", "Wedding Decorations", "Lights | Event Lighting", "Wood Slabs & Tree Slices", "Vases", "Apothecary Jars", "Banners", "Baskets", "Bell Jars, Cloches", "Beverage Bar Supplies", "Bird Cages & Birds", "Botanicals, Lavender, Sola Flowers", "Bottles & Jars", "Branches - Natural", "Buckets & Tubs", "Burlap Fabric, Jute, and Linen", "Cake Stands", "Candles", "Candle Holders", "Candy Buffet", "Chair Sashes, Banners, Signs", "Chalkboards", "Chandeliers", "Charger & Base Plates", "Confetti", "Corsage & Bouquet Supplies", "Craft Supplies", "Crates, Boxes, & Trays", "Crystal Decorations", "Easels & Frames", "Event Decor", "Favors", "Feathers", "Floral Supplies", "Flowers", "Greenery", "Home & Garden Decor", "Lanterns", "Mirrors & Mirror Stands", "Moss Natural & Artificial", "Nautical Decor & Decorations", "Packaging, Gift Wrapping", "Paper Lanterns & Parasols", "Paper Party Decorations", "Party Supplies", "Pots & Planters", "Placecard Holders,Table Numbers, Displays", "Preserved Flowers & Leaves", "Props, Pedestals, Risers", "Ribbon", "Silk Flowers", "Signage", "Shells - Sand", "Shepherds Hooks & Stanchions", "Sola Flowers", "Succulents & Cactus", "Table Runners & Toppers", "Terrariums", "Tote Bags, Welcome Bags", "Trees, Potted Plants", "Vases & Vase Fillers", "Wedding Cake Decorations and Toppers", "Wedding Decorations", "Wedding Signs", "Wedding Themes", "Wedding Trees & Wishing Trees", "Wood Crafts", "Wood Slabs & Tree Slices", "Wreath Making Supplies, Frames, Forms", "Gifts - Holiday Decorations", "Gifts Under $25", "Ideas & Inspiration", "Shopping Cart", "About", "Shipping", "Return Policy", "Contact", "FAQ", "Privacy Policy", "Terms and Conditions", "Read More", "Shipping", "Cart"],
"strong": ["Need Help?", "SUBSCRIBE", "wedding supplies", "party decorations", "home d cor", "Affordable Wedding & Event Decor", "Save 20-70%", "Need Help?"],
"span": ["*", "*", "Live Chat", "Shop Categories", "Customer Service: 7am - 5pm PST (M-F) | (831)768-8428", "Copyright 2017 Save-On-Crafts. All Rights Reserved. Designated trademarks and brands are the property of their respective owners. Use of this website constitutes acceptance of the Save-On-Craftsand Privacy Policy.", "Live Chat"]
}
},
{
"url": "http://www.carsurvey.org/",
"title": "Carsurvey.org - Car Reviews",
"content": {
"p": ["I feel as if this vehicle was custom built for me, love it", "Neat cruiser, comfort first, performance second", "Beast maaaaaaate!", "Best value for the money", "There are reviews on the site", "new reviews and new comments are in the Members section, awaiting approval"],
"td": ["2 days ago", "2 days ago", "3 days ago", "3 days ago", "18 hours ago", "19 hours ago", "19 hours ago", "19 hours ago"],
"a": ["Write a Review", "About", "Members", "Reviews by Region", "Write a Review", "About", "Members", "Reviews by Region", "BMW", "Buick", "Chevrolet", "Chrysler", "Citroen", "Dodge", "Fiat", "Ford", "Honda", "Hyundai", "Jeep", "Kia", "Mazda", "Mercedes-Benz", "Mercury", "Mitsubishi", "Nissan", "Oldsmobile", "Peugeot", "Pontiac", "Renault", "Saturn", "Subaru", "Toyota", "Vauxhall", "Volkswagen", "Volvo", "AC", "Acura", "Alfa Romeo", "Alvis", "AMC", "ARO", "Asia Motors", "Aston Martin", "Asuna", "Audi", "Austin", "Austin Healey", "Autobianchi", "Autocars", "Avanti", "Bajaj", "Bedford", "Bentley", "Birkin", "BMW", "Bombardier", "Bond", "Brennan-Mays", "Bricklin", "Bugatti", "Buick", "Cadillac", "Caterham", "Checker", "Chery", "Chevrolet", "Chrysler", "Citroen", "Commer", "Cord", "Dacia", "Daewoo", "DAF", "Daihatsu", "Datsun", "DeLorean", "DeSoto", "DeTomaso", "Dodge", "Eagle", "Edsel", "Ferrari", "Fiat", "Ford", "Franklin", "Freightliner", "FSO", "Geely", "Geo", "GMC", "Great Wall", "Grinnall", "Hillman", "Holden", "Honda", "HSV", "Humber", "Hummer", "Hyundai", "IHC", "IKA", "Infiniti", "Innocenti", "Inokom", "Iran Khodro", "Iso Rivolta", "Isuzu", "Iveco", "Jaguar", "Jeep", "Jensen", "JiangNan", "Kaiser", "Kia", "Kish Khodro", "Lada", "Laforza", "Lamborghini", "Lancia", "Land Rover", "Lexus", "Leyland", "Leyland DAF", "Lincoln", "Lotus", "Mahindra", "Maple", "Marcos", "Maruti", "Maserati", "Matra", "Maybach", "Mazda", "McLaren", "Mercedes-Benz", "Mercury", "Merkur", "Meson", "Meyers Manx", "MG", "Microcar", "Mitsubishi", "Morgan", "Morris", "Moskvitch", "Nash", "NAZA", "Nissan", "Noble", "Nova", "NSU", "Oldsmobile", "Oltcit", "Opel", "Packard", "Panther", "Perodua", "Peugeot", "Plymouth", "Pontiac", "Porsche", "Premier", "Proton", "Puma", "Pyonghwa Motors", "Quantum", "Qvale", "Ram Trucks", "Rayton Fissore", "Reliant", "Renault", "Riley", "Robert Jankel Design", "Rolls Royce", "Rover - Austin", "SAAB", "Saleen", "Samsung", "Santana", "Sao", "Saturn", "Scion", "Seat", "Sebring", "Sebring Vanguard", "Shelby", "Simca", "Singer", "Skoda", "smart", "Spartan", "SsangYong", "Standard", "Sterling", "Studebaker", "Subaru", "Sunbeam", "Suzuki", "Talbot", "Tata", "Tatra", "Tesla", "Tickford", "Toyota", "Trabant", "Triumph", "Troller", "TVR", "Vanden Plas", "Vauxhall", "Venturi", "Volga", "Volkswagen", "Volvo", "Wartburg", "Westfield", "Willys", "Wolseley", "Yugo", "Zagato", "ZAZ", "Zhengzhou Nissan", "Zhonghua", "ZXAUTO", "1997 Lexus LS", "2012 Audi A7", "1985 Dodge D100", "2007 Citroen C5", "More New Car Reviews", "1987 Chrysler New Yorker", "1995 Chevrolet Monte Carlo", "1995 Chevrolet Monte Carlo", "1995 Chevrolet Monte Carlo", "More New Comments", "Advertise on this site", "Privacy Policy"],
"strong": ["110091", "0", "3"],
"h1": ["Car Reviews by Manufacturer"],
"h2": ["Most Popular", "All Manufacturers"],
"h3": ["Newest Car Reviews", "Newest Comments", "Current Status"],
"span": ["Copyright 1997 - 2017 CSDO Media Limited", "|"]
}
},
{
"url": "http://www.hollywood.com/",
"title": "Hollywood.com - Best of Movies, TV, and Celebrities",
"content": {
"div": ["TRENDING NOW", "Hollywood.com Photo Archive", "Hollywood.com Esports", "Hollywood.com Discovery", "MovieTickets.com Discovery", "Wenn Penelope Cruz will always put her all into every role she wins, even if it means transforming herself physically. The Spanish actress has varied...", "Wenn Sean Penn reportedly resolved a dispute with fellow passengers during a recent flight to New York. The Mystic River actor had just boarded the...", "Wenn Rita Ora has hinted in a new interview that she and Cara Delevingne were more than just good friends. The 26-year-old singer and the...", "Wenn Charlie Sheen has stepped out in public with a new girlfriend. The 51-year-old actor showed off his blonde partner, known only as Jools, as...", "Wenn Tom Cruise's insistence on perfecting a zero-gravity stunt for The Mummy caused members of the film's crew to vomit. Tom stars as military operative...", "Wenn The Big Chill star Meg Tilly has made a return to Hollywood after 18 years to play Brad Pitt's wife. The actress stepped away...", "Wenn Rob Kardashian has slammed rumors he's dating reality TV star Mehgan James. A report published by Us Weekly magazine on Thursday (01Jun17) suggested that...", "Wenn Taylor Swift has been pictured with her actor boyfriend Joe Alwyn for the first time. News of the Bad Blood hitmaker's relationship with 26-year-old...", "NBC Ariana Grande has touched down in the U.K. ahead of her benefit concert for victims of the terrorist attack on her gig in...", "Wenn Alec Baldwin helped raise $5.1 million for New Jersey Democrats at an event in Collingswood, New Jersey, on Thursday night (01Jun17). The 30 Rock...", "Wenn Johnny Depp has claimed he was completely unaware his former managers were using his name to take out $40 million in loans. The fight...", "Wenn Carey Mulligan is reportedly expecting her second child. The Great Gatsby actress was pictured outside Sexy Fish restaurant in London with her husband Marcus...", "When it was first announced that Scarlett Johansson would play The Major in the wildly popular 'Ghost in the Shell' fans weren't happy, to...", "Billy Bob Thornton and the cast of Bad Santa 2 looked super naughty at AMC Loews Lincoln Square in New York City. Check out...", "Hulu's much anticipated drama The Handmaid's Tale premiered last night. This 10-part series is an adaptation from Margaret Atwood's 1985 novel of the same name, set...", "Julianne Moore and Michelle Williams premiered their new movie Wonderstruck at the 70th Cannes Film Festival. For a complete gallery of pictures, click here.", "Selena Gomez hosted WE Day celebrations at The Forum in California for her fifth year. WE Day is one of the largest Facebook non-profits in...", "Check out the super whimsical cast of NBC's Hairspray Live! before the musical premieres Wednesday, December 7th!", "Wenn / Paramount Pictures Thandie Newton wore a wig she was given on Mission: Impossible 2 to the BAFTAs on Sunday night (12Feb17). The Westworld...", "The Light Between Oceans premiered at the Venice Film Festival and co-stars and real-life lovers Michael Fassbender and Alicia Vikander were all smiles on...", "With the Margot Robbie stepping into the role of Maid Marian, and the currently-filming of Robin Hood: Origins, there's been a resurgence of interest...", "Tom Hanks is Forrest Gump, just like like Richard Gere is Edward Lewis in Pretty Woman; some actors have had such iconic movie roles,...", "Disney These days, Disney is known for pushing the envelope and hiding adult themes and jokes in their films. However, there was a time...", "ABC Television Network Abby, The Deadliest Catch Darby Stanchfield plays Abby Whelan, and she's come a long way to get to D.C. She actually grew up...", "There are many different kinds of family businesses, but one we hardly think about is acting. However, there are families that have actors going...", "It's no secret that Hollywood loves its cliches from action heroes who magically avoid every bullet fired at them to fat sitcom husbands who...", "HBO HBO's Silicon Valley just finished its first season. The show features a great cast of comedians, and it's managed to satirize the nerdy masculinity of...", "32.2x", "|", "19.2x", "|", "6.84x", "|", "6.16x", "|", "4.77x", "|", "4.22x", "|", "Powered by Crowdtangle", "1999-2017 HOLLYWOOD.COM, LLC. ALL RIGHTS RESERVED", "| | | |", "MOVIE, TV, AND CELEBRITY DATA PROVIDED BY AND IS THE COPYRIGHT OF"],
"a": ["CLOSE", "Click here - to use the wp menu builder", "Click here - to use the wp menu builder", "SIGN UP FOR OUR NEWSLETTER", "Meg Tilly Returns to Movies after Two Decade Hiatus to Play Brad Pitt's Wife", "Kathy Griffin in Tears at Press Conference", "Rob Kardashian Denies Reports He's Dating Reality Star Mehgan James", "Rita Ora talks 'ambiguous' relationship with Cara Delevingne", "Sean Penn Involved in Dispute During Flight to JFK", "Khloe Kardashian won't identify friend she claims is stealing from her", "Underwear On The Outside At The 'Captain Underpants' Premiere", "Penelope Cruz: 'I don't mind getting ugly for movie roles'", "Charlie Sheen goes public with new girlfriend", "Tom Cruise made The Mummy crew vomit with zero-gravity stunt", "Kathy Griffin in Tears at Press Conference", "Underwear On The Outside At The 'Captain Underpants' Premiere", "Khloe Kardashian won't identify friend she claims is stealing from her", "Underwear On The Outside At The 'Captain Underpants' Premiere", "'Baby Driver' Looks Like The Most Fun Movie In 2nd Trailer", "Go Behind the Voices of 'Captain Underpants: The First Movie'", "Something Is Wrong In the 'Murder on the Orient Express' Trailer", "Nicole Kidman lends her Balenciaga wedding dress to exhibition", "Penelope Cruz: I don t mind getting ugly for movie roles", "Sean Penn Involved in Dispute During Flight to JFK", "Rita Ora talks ambiguous relationship with Cara Delevingne", "Charlie Sheen goes public with new girlfriend", "Tom Cruise made The Mummy crew vomit with zero-gravity stunt", "Meg Tilly Returns to Movies after Two Decade Hiatus to Play Brad Pitt s Wife", "Rob Kardashian Denies Reports He s Dating Reality Star Mehgan James", "Taylor Swift Spotted with New Boyfriend Joe Alwyn for First Time", "Ariana Grande returns to U.K. as thousands make false ticket claims for Manchester benefit show", "Alec Baldwin Raises $5 million for Democrats", "Johnny Depp was unaware ex managers were using his name to get loans", "Carey Mulligan is Pregnant", "see more", "RED CARPET", "Travel To Tokyo For The Ghost in the Shell World Premiere", "The Cast Of Bad Santa 2 Spiced Up The Red Carpet At The NYC Premiere", "Hulu s The Handmaid s Tale Premieres", "Julianne Moore and Michelle Williams Premiere Wonderstruck at Cannes", "Selena Gomez, Demi Lovato, and Alicia Keys Celebrate WE Day", "The Cast Of NBC s Hairspray Live! Were Super Whimsical On The Red Carpet", "Thandie Newton wore Mission: Impossible II wig to the BAFTAs", "Michael Fassbender & Alicia Vikander Are Perfection At The Light Between Oceans Premiere", "see more", "DID YOU KNOW?", "All the Actresses Who Have Played Maid Marian", "12 Iconic Movie Roles That Famous Actors Turned Down", "The Original Drawing For Snow White Was Banned By Disney Because It Was Too Sexy!", "Facts You Never Knew About The Cast of Scandal", "11 Actors You Didn t Know Have Famous Grandparents", "15 Celebrity Dads You Didn t Know Have Hot Sons", "The 10 Most Overused Sound Effects in Hollywood", "21 Facts You Don t Know About Silicon Valley", "see more", "Teen Mom: OG Star Ryan Edwards Has Checked into Rehab", "E! News", "How To Train Your Dragon 3: Eveything We Know So Far", "moviepilot.com", "Alec Baldwin's Advice to Kathy Griffin on Trump Brouhaha: 'F--- Them All'", "The Wrap", "Alec Baldwin Defends Kathy Griffin in Wake of Trump Decapitated Photo Controversy: 'Ignore Him'", "People", "The Wonder Woman Scene That Pays Tribute To Superman", "CinemaBlend", "14 Of The Most Utterly Bizarre Things On Display At The M tter Museum", "Ranker", "Movies", "TV", "Celebrities", "Best Of/Worst Of", "Where Are They Now?", "Did You Know", "Buzzing", "Quizzes", "Pop Lists", "News", "SSNInsider", "MovieTickets.com", "EsportsHW", "Photo Archive", "About Us", "Contact Us", "Media Kit", "PRIVACY POLICY", "TERMS OF SERVICE", "COPYRIGHT ISSUES", "DISCLOSURE", "REPORT ABUSE", "BASELINE"],
"em": ["Want More?"],
"h1": ["WANT MORE?"],
"i": ["Facebook", "Google+", "Twitter", "YouTube", "Instagram"],
"h2": ["Sign Up For Our Newsletter!", "Sign Up For Our Newsletter!"],
"h3": ["FOLLOW US!", "LIKE US!", "TOPIC", "Category", "partners", "COMPANY", "Be friends with us"],
"time": ["Jun 2, 2017", "Jun 2, 2017", "Jun 2, 2017", "Jun 2, 2017", "Jun 2, 2017", "Jun 2, 2017", "Jun 2, 2017", "Jun 2, 2017", "Jun 2, 2017", "Jun 2, 2017", "Jun 2, 2017", "Jun 2, 2017", "Mar 17, 2017", "Nov 16, 2016", "Apr 26, 2017", "May 18, 2017", "Apr 28, 2017", "Nov 18, 2016", "Feb 14, 2017", "Sep 1, 2016", "Mar 7, 2017", "Aug 15, 2013", "Oct 5, 2016", "Apr 4, 2014", "Apr 22, 2016", "Aug 22, 2014", "Sep 21, 2015", "Jun 11, 2014"],
"span": ["Celebrities", "Movies", "Television", "Showtimes", "Search", "Esports", "Photo Archive", "The Latest", "Video", "Buzzing", "Pop Lists", "Did You Know?", "Where Are They Now?", "Featured", "Take A Sneak Peak At The Movies Coming Out This Week (8/12)", "Kathy Griffin in Tears at Press Conference", "Underwear On The Outside At The Captain Underpants Premiere", "Khloe Kardashian won t identify friend she claims is stealing from her", "Penelope Cruz: I don t mind getting ugly for movie roles", "Partners", "MovieTickets.com", "SSN Insider", "Privacy Policy", "Copyright Notice", "Terms of Use", "Report Abuse", "Videos", "Buzzing", "Red Carpet", "Esports", "Photo Archive", "Newsletter Signup", "Meg Tilly Returns to Movies after Two Decade Hiatus to Play Brad Pitt's Wife", "WENN", "Kathy Griffin in Tears at Press Conference", "WENN", "Rob Kardashian Denies Reports He's Dating Reality Star Mehgan James", "WENN", "Rita Ora talks 'ambiguous' relationship with Cara Delevingne", "WENN", "Sean Penn Involved in Dispute During Flight to JFK", "WENN", "Khloe Kardashian won't identify friend she claims is stealing from her", "WENN", "Underwear On The Outside At The 'Captain Underpants' Premiere", "Michael Chaney", "Penelope Cruz: 'I don't mind getting ugly for movie roles'", "WENN", "Charlie Sheen goes public with new girlfriend", "WENN", "Sign Up for Our Newsletter!", "Follow #hollywood", "THE LATEST", "Hot on Facebook"]
}
}
]
I have crawled 500K webpages and stored them in a Json file. Now, I am trying to read it. The whole file is 2GB, so I am unable to share the whole file.
I understand Json parser is getting some unexpected character (s) in the file but I am unable to find which line in the json file is erroneous. Is there any way I can find out the faulty line in the json file?
Edit
Main code in processing webpage contents is as follows.
for (Element element : elements) {
String tagName = element.tagName();
if (Util.isValidTag(tagName)) {
String textValue = Util.removeNonPrintableChars(element.ownText()).trim().replace("\"", "\'");
if (!textValue.isEmpty()) {
if (tagTextMap.containsKey(tagName)) {
tagTextMap.get(tagName).add(textValue);
} else {
ArrayList<String> arr = new ArrayList<>();
arr.add(textValue);
tagTextMap.put(tagName, arr);
}
}
}
}
I just removed non-printable characters and also replace double quotes by single quote, that's it.
Update
I found the problematic section in the json file.
{
"url": "http://www.kudzu.com/",
"title": "Atlanta roofers, hvac, plumbers, electricians and other businesses - reviews, coupons and cost estimates from your neighbors.",
"content": {
"h2": ["From Our Experts", "Recent Projects", "Recent Articles", "What It Costs", "Review a Business", "What It Costs", "Other Markets"],
"body": ["\"],
"span": ["Area", "Area", "Cost"]
}
}
This part - "body": ["\"], is the source of problem. I can understand now why its causing the problem.
It seems you are having trouble with escaping special characters. See this list of special characters used in JSON :
\b Backspace (ascii code 08)
\f Form feed (ascii code 0C)
\n New line
\r Carriage return
\t Tab
\" Double quote
\ Backslash character
So, while dumping json you need to escape this special characters. Fortunately every json library's has way to do this job. As it seems you have used JSON.simple toolkit, you can use JSONObject.escape() method to escape the special characters.
I also faced same issue
Unexpected character (s) at position 226025.
While reading json file using code, which is mention below :
JSONParser jsonparser = new JSONParser();
try {
JSONObject jsonObj = (JSONObject)jsonparser.parse("filepath");
System.out.println((String) jsonObj.get("id"));
}
catch(Exception e) {
e.printStackTrace();
}
Then I simply updated my code using fileReader Object in my code, it worked:
JSONParser jsonparser = new JSONParser();
try {
JSONObject jsonObj = (JSONObject)jsonparser.parse(new FileReader("filepath"));
System.out.println((String) jsonObj.get("id"));
}
catch(Exception e) {
e.printStackTrace();
}

Swagger API Annotation for Java using Enum as options which break request

I have a class defined called Website Locale which lits all supported locales for my site
public enum WebsiteLocale {
AU ("au", 5, "en", "AUD"), // Australia
CA ("ca", 6, "en", "CAD"), // Canada
DE ("de", 1, "de", "EUR"), // Germany
ES ("es", 1, "es", "EUR"), // Spain
ES_US ("es-us", 2, "es", "USD"), // USA, Spanish language
EU ("eu", 4, "en", "EUR"), // Europe: English and Euros
FR ("fr", 1, "fr", "EUR"), // France
FR_US ("fr-us", 2, "fr", "USD"), // USA, French language
IT ("it", 1, "it", "EUR"), // Italy
NL ("nl", 3, "en", "EUR"), // Netherlands
UK ("uk", 1, "en", "GBP"), // UK
US ("us", 2, "en", "USD"); // USA
... getters / setters... }
In my API resource I have the following annotation
#GET
#Path("/countries")
#ApiOperation("Get countries")
#CacheControl(maxAge = 1, maxAgeUnit = TimeUnit.HOURS)
#Override
public List<CountryDto> getCountries(
#QueryParam("websiteLocale") #ApiParam(required = true, defaultValue = "uk") final WebsiteLocale websiteLocale) {
return delegate.getCountries(websiteLocale);
In the Swagger API test page for that endpoint it gives the accepted values as the Enum literals themselves
e.g. AU, CA, DE, ES, ES_US, EU, FR, FR_US
This breaks the controller (404 not found response) because it is looking for the associated string key for that enum
i.e. au, ca, de, es, es-us, eu, fr, fr-us
I had a look through swagger but could not see any specific annotation to look for a part of the enum properties.
Any ideas?
Thanks

java creating blank spaces with printf

When I run my program, I get this:
run:
Heat Index: Key West, Florida
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
____________________________________________________________________________________________________________________________________
Temperature: 70.3 70.8 73.8 77.0 80.7 83.4 84.5 84.4 83.4 80.2 76.3 72.0
Humidity: 69.0 67.0 66.0 64.0 66.0 69.0 67.0 67.0 70.0 69.0 69.0 70.0BUILD SUCCESSFUL (total time: 0 seconds)
I want to display this so that the months align with each column of numbers, like Jan aligns with the first column of numbers and so on. I know that there are 7 blank spaces between each column of number if the months are aligned. The thing is, I don't know how to create blank spaces, like blank spaces so the months won't show up on top of the Temperature: heading, with printf. Any help will be greatly appreciated.
You need to use System.out.printf() and passing the appropriate flags for the width, see here for the syntax for formatting.
String[] months =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"};
Double[] temper =
{70.3, 70.8, 73.8, 77.0, 80.7, 83.4, 84.5, 84.4, 83.4, 80.2, 76.3, 72.0};
Double[] humid =
{69.0, 67.0, 66.0, 64.0, 66.0, 69.0, 67.0, 67.0, 70.0, 69.0, 69.0, 70.0};
System.out.printf(" %7s%7s%7s%7s%7s%7s%7s%7s%7s%7s%7s%7s\n",
(Object[])months);
System.out.printf("________________________________________"
+ "________________________________________________________\n");
System.out.printf("Temperature:%7.1f%7.1f%7.1f%7.1f%7.1f"
+ "%7.1f%7.1f%7.1f%7.1f%7.1f%7.1f%7.1f\n",
(Object[])temper);
System.out.printf(" Humidity:%7.1f%7.1f%7.1f%7.1f%7.1f"
+ "%7.1f%7.1f%7.1f%7.1f%7.1f%7.1f%7.1f\n",
(Object[])humid);
try this.. you can specify spaces between each print..
String[] day = {"Sun", "Mon", "Tues", "Friday","Saturday"};
for(String s :day){
System.out.printf("%15s", s);
}
This will print exactly four spaces plus the three taken up by the month. Also, if you just want to print Strings you don't really need printf. Below are two options.
System.out.printf(" %s", month);
or
System.out.print(" " + month);
I would also recommend coming up with a way to do this without hard coding the spaces. Maybe set up a loop to print spaces which can change the width.
try this
System.out.println("\n");

Categories