I am trying to use talend to check if the 4th character = 4 then I conversion S _ if not we keep the value
the input file is an Excel file
who can help me
row1.B.charAt(4) == '4'? StringHandling.CHANGE(StringHandling.LEFT(row1.B,9) ,"_","S"):row1.B
I have this error
[statistics] connected
Exception in component tMap_1
java.lang.NullPointerException
at projectname.test_0_1.test.tFileInputExcel_2Process(test.java:1140)
at projectname.test_0_1.test.runJobInTOS(test.java:1672)
at projectname.test_0_1.test.main(test.java:1540)
Either row1 or row1.B (use proper caps! attributes begin with lower case) are null
UPDATE: Regardint the comment to your question, then row1.B is null. Check for it and either control it in the condition ((row1.B != null) && (....)) or ((row1.B == null) || (...)) or (more probably) check your logic to assign a proper value to it.
A null pointer exception is caused when you dereference a variable that is pointing to null.
In you case either row1 or row1.B are null.
The cleanest way to do this is to write a user routine and then just call the function from tMap on the row input.
E.g. userFunction(row1.B)
Make the function output whatever string manipulation you need.
This also allows you to handle the case where the B cell in Excel is null. You can't do that in a one liner in tMap.
Related
I have a code that compares data but that data contains null values not blank spaces ("") they may/may not be same i guess but I tried comparing repetitive NULL values like
for(int i=0;i<length;i++)
{
String data=sample_data.getData();// contains about
1000 null rows
if(data.equals(null) || data.equals("") || data== null
||data.isEmpty())
System.out.print("No Data");
}
I could have used .contains but that wont work because it is in the loop.
None of the method makes it print the output as No Data I have tried using try catch as well because in order to make sure if theres any error found and was correct at the same time isEmpty() and .equals(null) were somewhere or the other throwing the exception as NULL but even after removing and simply using ==Null realizing the fact that data is itself null and comparing like null.equals wont work but in case of == I found that the error exception got changed to value as 1 thereafter the same error and I wasnt able to recognize this.
Its the sample here which I am showing I cant post the exact but the above makes quite clear. Is there any other way I could treat these NULL values.
Note: I dont want to use a loop to iterate data as well and each time comparing NULL values because already theres an outer loop for large set of values dont go by the sample code.
Restoring windows to factory settings will restore windows (as its name suggests); it won't spoil anything.
In this
String data=sample_data.getData();// contains about 1000 null rows
if(data.equals(null) || data.equals("") || data== null
you are apparently concerned that data may be null.
If indeed it is null, then the very first clause in your if statement will throw a null pointer exception... because you can't call the equals method on a null reference.
You want
if (data == null || data.isEmpty())
and that covers all the cases of nothing, except possibly the case where data is "some number of space characters", but I'll leave that for you.
I have two txt files with a specific structure. There should be som empty rows and rows with some data. Something like this:
#RELATION Table
#RECORD 1
ID '5'
SOMETHING '10'
The point is, there can be 10 'empty' rows in one file and there can none in second and if the data equals, it should not matter. Any ideas how to effectively do it with big files ?
BufferedReader should be used to read from file, supplying a FileReader to its constructor:
https://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html
So you will have two of them, one for each file.
Have an "infinite loop" such as: while(true){}
Within this container loop, you should have two internal loops, one for each file.
In each internal loop, using the method readLine() you should advance the cursor to the next line.
declare this outside of the container loop:
String lineFromFileA, lineFromFileB;
and then:
while((lineFromFileA = bufferedReaderA.readLine()) != null){
if(!lineFromFileA.isEmpty())
break;
}
do the same with lineFromLineB.
an alternative to the above loop is:
while((lineFromFileA = bufferedReaderA.readLine()) != null && lineFromFileA.isEmpty());
After the two internal loops, both lineFromFileA and lineFromFileB are either null or has a value that is not an empty String.
If both are null, then you are done with the comparison, the two files are equal and you may return true from the function.
If one contains null and the other does not, return false. The files are different.
If both are not null, then check the equals() method if the two Strings are identical, if they are not, return false from the function. If they are equal, do nothing, the next iteration of the container loop will handle the next line.
I'm parsing a CSV using Processing's Table interface, but some rows are missing some data. I want to pull all the data available into my table, but I'm not sure how to handle the missing data--I keep getting NullPointerException when I loop over the table with dataTable.getInt on the missing values.
I don't have a background in statically typed languages, so I've no idea how to conditionally assign this data short of putting a separate try/catch around each assignment. Surely there's a better way?
Before calling dataTable.getInt method check if dataTable is not null like
if(dataTable != null) {
int my_nt = dataTable.getInt
}
//else skip since it is empty
Since your're using getInt--you should perform a regex search/replace ,<not numeric>, with ,<some int>,. In your case it may be as simple as replacing ,, with ,0,
Also, as Hassan suggests, double check that dataTable is not null.
Ok, so I figured out a way to do this:
First, call dataTable.makeNullEmpty(), which turns all the null values into empty strings.
Then, you can use a pattern like this:
String total_value = dataTable.getString(i, 4);
if(total_value.length() > 0) s.total_value = parseInt(total_value);
and you get assignment only if an int is there to be parsed.
if (current.leftChild.iData != '+' && current.rightChild.iData != '+')
For this line of code i am trying to check if the leftChild of the current node and the rightChild of the current node both == '+' Or character plus sign. If either of them do not = the character + i want to execute other code. I am getting a null pointer exception for this line and the method i use to call this line of code.
iData is just the information inside the node.
If you are getting a null pointer exception that means either the following cases.
1. current is null.
2. leftChild is null/ rightChild is null.
3. iData is null
But since you haven't provided a lot of details. I won't be able to help you.
Either current.leftChild or current.rightChild (or current itself) is not being set properly and is null. Trying to access the members of null results in a NullPointerException.
If current, current.leftChild or current.rightChild is null, you will get a NullPointerException.
You need to perform a null check first.
Use breakpoints to see the values of current.leftChild.iData and current.rightChild.iData.
Or you can write:
System.out.println("leftChild: " + current.leftChild.iData);
System.out.println("leftChild: " + current.rightChild.iData);
You will need to check the changes to these values because somewhere in your code it has set them to null. Once they are null, the system will give you the NullPointerException because those objects no longer exists.
First of all try printing each piece of that to find out what is null, you should get an NPE when you get to the piece that is causeing you trouble, this will seperate left and right into seperate failures. Note that if you make these seperate lines and both are failing you will only get the failure for the first one.
Now:
if (current.leftChild.iData != '+' && current.rightChild.iData != '+') For >this line of code i am trying to check if the leftChild of the current node and >the rightChild of the current node both == '+' Or character plus sign. If >either of them do not = the character + i want to execute other code
The code you wrote will not (once its not throwing exceptions) test what you say you want it to. You said you want to see if either is != to '+', but this code only tests if both are != '+', therefore you are missing some conditions which I believe that you inteded to catch. In fact if you really want to execute other code if either does not equal '+' then what you want is
if (current.leftChild.iData == '+' && current.rightChild.iData == '+')
{
//code you execute if both are equal to '+'
}
else
{
//code you execute if either (or both) is not equal to '+'
}
So I am making a URL request to fetch a stream of data into a BufferedReader. The data that I am fetching has values "null" for various fields. The while condition I am using to read all the data is:
while (((inputLine = in.readLine()) != null))
so the condition is breaking in between, when it encounters a null value, which is actually not the EOF but only a field value. How do I resolve this?
When you read a line, it will never be null until it reaches the end of the data. If there's no data in the line, it will just be an empty string instead.
You haven't shown enough code to explain why you're getting a NullPointerException, but you really need to understand that you won't see any "null values" before reaching the end of the data.
To work out why you're getting a NullPointerException:
Look at the line indicated in the stack trace
Identify every dereferencing operation
Either put a breakpoint on that line, or add some logging, or split the line into multiple statements so that each statement only has a single dereferencing operation
That should let you work out exactly which value is null, causing the exception to be thrown. What you need to do to fix it will depend on what you're trying to do and which value is null - we don't have enough information to help you on that front at the moment.