How determine if Java object is null or not in Tasker? I want a Tasker task that reads SMS from a particular person and extracts some information out of the latest message.

For example, I get a lot of messages from my bank due to the transactions I make. At the touch of a task, I want to know my latest bank balance. Normally, I would get the latest SMS from my bank and find out the balance from it. I want Tasker to do this.

I am aware that Tasker can read messages when they arrive. But we have to make a profile that does it. This is not my use-case. It's more on-demand.

Here is the task I tried to create to that effect:

Flash Roam (10)
    A1: Java Function [ Return:cr Class Or Object:CONTEXT Function:getContentResolver
{ContentResolver} () Param: Param: Param: Param: Param: Param: Param: ] 
    A2: If [ cr !Set ]
    A3: Flash [ Text:Ok Long:Off ] 
    A4: End If 


I am unable to ascertain if cr is null or not.

What is the correct way to check it? Or is this even possible in Tasker?
There are two ways you can do null checking of Java objects.

The first way, direct from the userguide, is checking of the object Equals null:

If
A Java object can be directly referenced in a condition. Null-value objects are replaced with text representation null.
Examples:
If, arr[0][0] eq 45
If, arr[0].length &gt; 3 
If, lightlevel Equals null


The problem with this is that the string &quot;null&quot; will also match the condition. In your case, that's not a concern, but my second method provides a way that can distinguish between the two for other cases.

The second way takes advantage of Tasker's built-in error checking. If you have an object and need to check whether or not it's null:

Use a Java Function action. For &quot;Object or Class&quot;, use the object in question, then for &quot;Function&quot; select &quot;toString {String} ()&quot;*. Lastly, make sure &quot;Continue Task After Error&quot; is checked. You don't need a return value here.
Follow the Function with an If action, which tests if the variable %err is set (or isn't set).
If %err is set, the object is null. Otherwise, it's not null.

%err will not be set if the object is the string &quot;null&quot;, because &quot;null&quot;.toString() is perfectly valid code.
* If your only option in the Function list is &quot;assign {...} ()&quot;, then you're working with a primitive type - a number, boolean, or character. Those can't be null, so checking is unnecessary.