[Solved] How to read doc file using Poi?

You are trying to open a .docx file (XWPF) with code for .doc (HWPF) files. You can use XWPFWordExtractor for .docx files. There is an ExtractorFactory which you can use to let POI decide which of these applies and uses the correct class to open the file, however you can then not iterate by page … Read more

[Solved] How to end while loop in Java

You don’t change the value of a (which is true by default) to false, you just call a method that will return false but nothing is set to this returned value. Change your code to this: package files; public class EndLoopWithBooleanMethod { static boolean a = true; public static void main(String[] args){ while(a) { //This … Read more

[Solved] Why do I get a $ sign in decompiled java classes full with errors? [closed]

What you’re seeing is Java’s internal representation of the anonymous inner classes. Java implements these by creating classes with generated names, which — like all inner classes — are based on adding $ and a suffix to the name of the containing class. (There are some other changes made to support the inner class’s ability … Read more

[Solved] How can I form combinations out of a sentence

I think you could do something like: String[] words=title.split(” “); String printWord = “”; for (int i = 0; i < words.length; i++) { printWord += words[i] + ” “; // Add the space for newly appended words System.out.println(printWord); } The above, will just print the following The The amazing The amazing spider The amazing … Read more

[Solved] Null Pointer Exception during MySQL database write

Check documentation of ResultSet.getString:http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html#getString%28int%29 String getString(int columnIndex) throws SQLException Returns: the column value; if the value is SQL NULL, the value returned is null According to this your code is vulnerable to null pointer exception at following places: if (!results.getString(“level”).isEmpty()) { ……. } else if (!results.getString(“thesisTitle”).isEmpty() || !results.getString(“thesisAdvisor”).isEmpty()) { ………. } else if (!results.getString(“company”).isEmpty()) { … Read more

[Solved] Java – Getting Difference Between Two Lists [closed]

For example, to see who is just a coach and not also a teacher without losing your list of coaches: List<String> coaches = new ArrayList<>(); coaches.add(“Josh”); coaches.add(“Jake”); coaches.add(“Tyler”); List<String> teachers = new ArrayList<>(); teachers.add(“Josh”); teachers.add(“Jake”); List<String> CoachesNotAlsoTeachers = new ArrayList<>(); CoachesNotAlsoTeachers.add(coaches); CoachesNotAlsoTeachers.removeAll(teachers); for (String name : CoachesNotAlsoTeachers ) { System.out.println(“Name is: ” + name); } … Read more

[Solved] Need a little with an audio player in java [closed]

First of all, if you want to play sounds that aren’t looped and are longer than a few seconds, you shouldn’t be using Clips. You’re going to need to use SourceDataLines, which can read audio data in several different formats (consult AudioFileFormat.Type for specifics) via streams. As for your questions: Mixers, Lines, and Ports are … Read more

[Solved] function for Phone number to words in java for multiple digits [closed]

Call numToWords with your number. Otherwise if you already have a string just pass it and skip the String.valueOf(number) calling directly the split private static final HashMap<String, String> mapping; static { mapping = new HashMap<>(); mapping.put(“0”, “Zero”); mapping.put(“1”, “One”); mapping.put(“2”, “Two”); mapping.put(“3”, “Three”); mapping.put(“4”, “Four”); mapping.put(“5”, “Five”); mapping.put(“6”, “Six”); mapping.put(“7”, “Seven”); mapping.put(“8”, “Eight”); mapping.put(“9”, “Nine”); … Read more

[Solved] How can I re-run java code from the java program?

Why dont you use recursion. put the file writing code into one method. Giving blueprint below please try to implement that way. public class CSV { String data1; String data2; boolean runnung=false; int globalvariable = 1; public void fileWrite(){ FileInputStream ar= new FileInputStream(“filelocation”); FileWriter dr= new Filewriter(“datafile”+globalvariable.csv”); dr.close(); //while (running) { if (data=some number) { … Read more

[Solved] Create a map with values of one map as key and values of each map as values from a list of maps [closed]

You want something like this: List<Map<String, String>> result = four.stream() // iterate the Map with values .map(map -> map.entrySet() // .. for each one .stream() // .. stream and collect .collect(Collectors.toMap( // .. into a new Map e -> one.get(e.getKey()), // .. with a key from the `one` Map Map.Entry::getValue))) // .. and the same … Read more

[Solved] ReportPayment() method in main is giving errors

Reworked the answer: I tried to run the code myself and with a little tweaking it works perfectly fine. We are getting there. I think thi is the whole thing you should need! This should now fix your error aswell as fit the requirements you have. I changed: renamed ReportPayment() to reportPayment() removed te space … Read more