How To Deal With String Value Of Null In Data File
Feb 24, 2015
I have table data I'm trying to read . However one column is populated with the word "null". I guess java does not like dealing with the word null and throws errors.
When I try a block like : if ( rsrow.getString(insCol) = "null") {
I get and error .
If I try :
cmp = rsrow.getString(insCol);If I try:If I try:
if (cmp = "null") {
I get an error
If I try to use a replace function like:
System.out.println(cmp.replace("null", "0"));
Just to see if replace works I get and error.
What is the BEST way to replace this string value with something like "0" when I come across it with out jave throwing an error? I want it such that every time I come across the word "null" I can repalce it with "0".
I'm just trying to append new employee information to a previously created file. When I type yes to add new employee and enter a string, the data does not appear in the file.
Java Code:
public class Records { public static void main(String [] args) throws IOException { Scanner input = new Scanner(System.in); FileWriter fw = new FileWriter("dbs3.java", true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter pw = new PrintWriter(bw);
I need to get the html in string when i hit the hit the jsp in servlets basically i need to put the output of jsp in pdf file when i hit one link i need to download that data in pdf file. I am using itextpdf.
//Get the output stream for writing PDF object OutputStream outStream=pResponse.getOutputStream(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
[Code] ....
I need to convert the sample download.jsp to html so that i can parse
I'am new to java, this question may have been asked earlier but I'm not getting the exact answer.I want to add data from database into at and display it through jsp. But empty or null values is shown i.e no data is being displayed and when I execute the same sql query which is used in code in sql server then required output is displayed. My java code is:
Java Code:
public List < Alarm_Bean > get_Count(String system_Name) { if (system_Name.equals("MPS")) { try { con = getConnection(); stmt = con.createStatement();
/** * Compute shortest paths in a graph. * * Your constructor should compute the actual shortest paths and maintain all the information needed to reconstruct them. The returnPath() function should use this information to return the appropriate path of edge ID's from the start to the given end. * * Note that the start and end ID's should be mapped to vertices using the graph's get() function. */ class ShortestPaths { Multigraph graph; final int INF = Integer.MAX_VALUE; PriorityQueue<Integer> Q;
[Code] ....
I followed someone else psuedocode very closely but for whatever reason, my edge[] array is just full of null data, which means I can't actually return the shortest path. Why that's happening/how to fix it? Maybe I'm not understanding dijstra's correctly.
What I am trying to do is extract the digits from between the words 'deal' and 'of'. I was wondering if this was possible to do with a regular expression or if I should just use a scanner.
UNIQUE Passive - Cleave: Basic attacks deal 20% to 60% of total Attack Damage as bonus physical damage to enemies near the target on hit (enemies closest to the target take the most damage).
Is there a regular expression that I could use in order to extract the '20' and the '60' from the above text. Below is what I have tried, but does not work.
(?<=deals)(d+(?=%))(?=of)
just to make a clarification, these numbers will not be the only numbers and the strings themselves will change. Everything can be considered a variable. The only constants between each string would be the words 'deal' and 'of'. The regex pattern "d+" is not a viable expression for my case
I am trying to export data from a jtable to a pdf report but every time i try running the code it gives me this exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at GUI.QC_receiving_book.printButtonActionPerformed(QC_receiving_book.java:309) at GUI.QC_receiving_book.access$600(QC_receiving_book.java:26) at GUI.QC_receiving_book$7.actionPerformed(QC_receiving_book.java:165) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
[Code] ....
I tried avoiding the null exception by using the if statement but it didn't work. The row I choose from the table is full meaning there are no empty attributes. and all the data are imported from a mysql database to the table as String so there can't be any casting errors.
This is the part of the source code with the problem and i will also post the printing method. I tried debugging the class and when stepping into the first if statement it opened the jTable.java file and pointed at the getSelectedRow() method and this sentence "variable information not available.source compiled without -g option"
private void printButtonActionPerformed(java.awt.event.ActionEvent evt) { if(samplesTable.getSelectedRow() >= 0){ int row = samplesTable.getSelectedRow(); System.out.println(row); for(int x=0;x<samplesTable.getColumnCount();x++){ String value = samplesTable.getModel().getValueAt(row, x).toString();
So, let's say I have a pdf that looks like an exam or anything that has answer choices and an oval to fill in.
So, if I want to create a program that fills in some of those ovals, I would first need to find the coordinates? I can use something like gimp?
And once I have those coordinates, what do I do? Like do I extract the oval image and replace it with a filled in one? Is there a library that lets me do this - also lets me set the size to make sure the new filled in oval image is the same size?
In the case that vehicle.color is null what will happens? A null pointer error?
null will be concatenated to the string in vehicle.color place? or will not concatenate anything in the place of vehicle.color I'm asking that because I do not know if I have to check for null in each property of vehicle that I must concatenate (there are a lot of properties in the Vehicle object and some may not been set (they will return null).
I've been beavering away with Java for a few months. But as with all languages the String implementation looks designed to trip up even experienced programmers.
My current development gets data from various sources outside my control. When I get a string I want to test if it is empty/null/or whatever. Simple enough one thinks.
But if you search the internet you see everone seems to have a slightly different approach. So what is the best way of determining that a string is not useful to you?
I've had success with this
if(string == null || string.length() == 0)
But I've seen people using methods - not necessarily of String (e.g equals, empty) and regular expressions.
What is the best approach to this considering coding efficiency and/or processing efficiency (accepting you'd have to be processing a lot of strings for the latter to be an issue).
I'am trying to converting string data into xml data using xml beans and StringEscapeUtils.This is work fine but in one case it if the data contains special characters.
Code snippet -------------------- import org.apache.commons.lang3.StringEscapeUtils; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; public class ParseXMLData { public static XmlObject parseXML(String stringXML) { XmlObject xmlObject = null;
[Code] ....
success case --------------------------- i/p------<aaa><bbb>This converts string to xml</bbb></aaa> o/p---<aaa><bbb>This converts string to xml</bbb></aaa>
Failer case ----------------- i/p----<aaa><bbb>This fails if it contains < symbols</bbb></aaa> expected o/p----<aaa><bbb>This fails if it contains < symbols</bbb></aaa>
Observed that it converts < to '<' but as per xml rules, if data contains '< ' it fails. I want to convert staring and end tags to xml format and if data in b/w middle of starting and ending tags do'n need to convert it. How to do it.
I've a vertical-bar-delimited file where most elements contain text, some contain whitespace, and some are empty. Examples:
62RG|fe|Pencil Financial Group, LLC||doug@pencil.com|||85637889|Cross, Ben|bcross@godaddy.net|Bernard|Cross|Ben||315 One Tree Hill Terrace|Lafayette|LA
String str_arry = innline.split( "|", 17); lisst.add( new Contact( str_arry));
and my Contact class has the constructor
public Contact( String[] str_arry) { for( int ii = 0 ; ii < str_arry.length ; ii++ ) { if( str_arry[ii].matches("^s+$")) { str_arry[ii] = null; System.out.println("hit a null");
[Code]...
I expect the for-loop in the constructor to find any elements containing whitespace characters and set them to null for subsequent assignment.And when the code runs I do see some hit-statements pop up, so the detecting part is working.
But when I then process the list and access a Contact object and test fields for nulls I don't find any ie
if( aContactObj.getfFCity() == null) System.out.println("city is null");
never prints when it should.
What's the trick? Or is my approach wrong and if so what should it be?
I am trying to parse a XML string into `org.w3c.dom.Document` object.
I have looked at solutions provided [here](xml - How to convert String to DOM Document object in java? - Stack Overflow), [here](How to create a XML object from String in Java? - Stack Overflow) and a few other blogs that give a variation of the same solution. But the `Document` object's #Document variable is always null and nothing gets parsed.
Here is the XML
XMLMappingValidator v = new XMLMappingValidator("<?xml version="1.0" encoding="utf-8"?> " + "<mapping> " + "<container> " + "<source-container>c:stem.csv</source-container>
[Code] ....
When I call **v.getXML().toString()** I get `[#document: null]`
Clearly, the parse is failing. But I don't understand why.
I am trying to parse a XML string into `org.w3c.dom.Document` object.
I have looked at solutions provided [here](xml - How to convert String to DOM Document object in java? - Stack Overflow), [here](How to create a XML object from String in Java? - Stack Overflow) and a few other blogs that give a variation of the same solution. But the `Document` object's #Document variable is always null and nothing gets parsed.
Here is the XML
Java Code:
XMLMappingValidator v = new XMLMappingValidator("<?xml version="1.0" encoding="utf-8"?> " + "<mapping> " + "<container> " + "<source-container>c:stem.csv</source-container>
[Code] .....
When I call Java Code: **v.getXML().toString()** mh_sh_highlight_all('java');
I get Java Code: `[#document: null]` mh_sh_highlight_all('java');
Clearly, the parse is failing. But I don't understand why.
Question 1: I am working on an assignment where I have to remove an item from a String array (see code below). When I try to remove an item after entering it I get the following error "java.lang.NullPointerException." I am not sure how to correct this error.
Question 2: In addition, I am having trouble figuring out how to count the number of occurrences of each string in the array and print the counts. I've been looking at other posts but they are more advanced and I have not yet learned how to use some of the tools they are referring to.
private void removeFlower(String flowerPack[]) { // TODO: Remove a flower that is specified by the user Scanner input=new Scanner(System.in); System.out.println(); System.out.println("Please enter the name of the flower you would like to remove:
I get a null pointer error on line 17 of the following fragment. I suspect it has to do with the way I am reading the file, but I'm unsure. I can provide more information or code if necessary.
JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES ); int userInput = jfc.showOpenDialog( null ); if( userInput == JFileChooser.CANCEL_OPTION ){
I would like to understand how does multipart/form-data works during file upload scenario's, Does it chunks the data from client to server while transferring the files ?
By using FileReader, FileWriter and their constituents, I am creating a file to contain employee information ( name, age, hours, etc. ). The user is to input all of the data on a single line and we were asked to implement StringTokenizer to assign that data to the file. I have never used the StringTokenizer before, but I have a rough idea how it is to function. I used pw.println to test what I have so far, now I would like to let the user build the initial file with the "first employees" of the company, and then view the file, and then go back and append new employee data to that same file. My question is, how can I take the user input as a StringTokenizer and add that to the file?
In the for loop below, I thought I would see if it would work, but it does not. The loop only executes once and does not allow me to enter data.
public class Records { public static void main(String [] args) throws IOException { Scanner input = new Scanner(System.in); FileWriter fw = new FileWriter("dbs3.java"); BufferedWriter bw = new BufferedWriter(fw); PrintWriter pw = new PrintWriter(bw); System.out.println("NEW EMPLOYEE DATA SHEET"); System.out.print("Number of new employees: "); int number = input.nextInt();
I am trying to remove a line based on user input. myFile.txt looks like:
Matt Brian John
However when I enter "Brian" (to remove this line), It is deleted on the temp file (myTempFile.txt), but not renamed back to the original file (myFile).
I am creating a program where it reads the data inside a file and then places this data into arrays. The file I created has numbers 1-30 in it, file named, testing1.txt .
public class Test { public static void main(String[] args) { Car c = new Car(); c.setInf("toyota", "red"); System.out.println("name: "+ c.brand + " colour: " + c.colour);
[code]....
Why do I get the result brand null, colour null? I know what null means but what am I missing here?