I'm developing an Android App using Google Map and clustering.
I'm getting a Null Pointer Exception when I try to remove an Item from the cluster manager.
E/UncaughtException: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.remove(java.lang.Object)' on a null object reference
at com.google.maps.android.quadtree.PointQuadTree.remove(PointQuadTree.java:176)
at com.google.maps.android.quadtree.PointQuadTree.remove(PointQuadTree.java:171)
at com.google.maps.android.quadtree.PointQuadTree.remove(PointQuadTree.java:153)
at com.google.maps.android.clustering.algo.NonHierarchicalDistanceBasedAlgorithm.removeItem(NonHierarchicalDistanceBasedAlgorithm.java:95)
at com.google.maps.android.clustering.algo.PreCachingAlgorithmDecorator.removeItem(PreCachingAlgorithmDecorator.java:61)
at com.google.maps.android.clustering.ClusterManager.removeItem(ClusterManager.java:161)
at com.company.myApp.controllers.MapClusterManager.removeItem(MapClusterManager.java:72)
The code that is throwing the exception is the following:
if(clusterManager.getAlgorithm().getItems().contains(mapClusterItem)) {
clusterManager.removeItem(mapClusterItem); // <-- NPE here
clusterManager.cluster();
}
As you can see I'm actually checking the existence of the item before the deletion.
The clustering setup follows:
clusterManager = new ClusterManager<MapClusterItem>(context, googleMap);
algo = new NonHierarchicalDistanceBasedAlgorithm<MapClusterItem>();
clusterManager.setAlgorithm(algo);
The problem is that PointQuadTree.remove(double x, double y, T item) (Google Library) throws the Exception.
Does anyone know how to solve it?
The GridBasedAlgoritm doesn't fit my case. I want to use the
NonHierarchicalDistanceBasedAlgorithm
.
I'm using the cluster library from Google Maps Utils.
compile 'com.google.maps.android:android-maps-utils:0.4.+'
It's a bug in the library, and it's going to be delivered a fixed version soon as said here:
https://github.com/googlemaps/android-maps-utils/issues/348
Related
I am getting below error while calling
dynamoDBMapper.scan(Person.class, new DynamoDBScanExpression())
java.lang.NullPointerException: null
at com.amazonaws.services.dynamodbv2.model.ScanRequest.setScanFilter(ScanRequest.java)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.createScanRequestFromExpression(DynamoDBMapper.java:1692)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.scan(DynamoDBMapper.java:1569)
at com.amazonaws.services.dynamodbv2.datamodeling.AbstractDynamoDBMapper.scan(AbstractDynamoDBMapper.java:236)
With the same dynamoDBMapper, dynamoDBMapper.save(person1) is working fine.
The NullPointerExecption is coming inside of ScanRequest.setScanFilter method of the AWS SDK.
Although, the method setScanFilter has only one line of code, the stacktrace is not showing the line-number where the exception occurred.
The method ScanRequest.setScanFilter looks like this.
public void setScanFilter(java.util.Map<String, Condition> scanFilter) {
this.scanFilter = scanFilter;
}
Not sure how this.scanFilter = scanFilter can cause a NullPointerException
Spring Boot - 2.2.6.RELEASE
DynamoDB SDK - 1.11.555
Java - Corretto-8.242.08.1
#ShrinivasShukla I also found the NPE when Contrast is wired up in Application. In my case Probably Contrast is disabling/blocking scanRequest.setScanFilter(scanExpression.getScanFilter() to work.
Am calling a popup dialog, this throws an error.
This code previously worked, but i recently uploaded a new build and my new build now produces an error message on the 15/07/2019
public Command showPopupDialog(Component c). this is the method in the Dialog class am calling.
Getting the following error message
java.lang.NullPointerException
at com.codename1.ui.plaf.Border.paintBorderBackground(Border.java:1435)
[EDT] 0:0:0,19 - Exception: java.lang.NullPointerException - null
at com.codename1.ui.plaf.Border.paintBorderBackground(Border.java:1267)
at com.codename1.ui.Component.paintBackgroundImpl(Component.java:2661)
at com.codename1.ui.Component.paintComponentBackground(Component.java:2625)
at com.codename1.ui.Container.paintComponentBackground(Container.java:2546)
at com.codename1.ui.Component.internalPaintImpl(Component.java:2239)
at com.codename1.ui.Component.paintInternalImpl(Component.java:2228)
at com.codename1.ui.Component.paintInternal(Component.java:2203)
at com.codename1.ui.Container.paint(Container.java:1639)
at com.codename1.ui.Form.paint(Form.java:4180)
at com.codename1.ui.Component.internalPaintImpl(Component.java:2255)
at com.codename1.ui.Form.internalPaintImpl(Form.java:4190)
at com.codename1.ui.Component.paintInternalImpl(Component.java:2228)
at com.codename1.ui.Component.paintInternal(Component.java:2203)
at com.codename1.ui.Component.paintInternal(Component.java:2171)
[EDT] 0:0:0,66 - Exception: java.lang.NullPointerException - null
at com.codename1.ui.Component.paintComponent(Component.java:2468)
at com.codename1.ui.animations.CommonTransitions.paint(CommonTransitions.java:1139)
at com.codename1.ui.animations.CommonTransitions.initTransition(CommonTransitions.java:469)
at com.codename1.ui.Display.initTransition(Display.java:1576)
at com.codename1.ui.Display.setCurrent(Display.java:1535)
at com.codename1.ui.Form.showModal(Form.java:2303)
at com.codename1.ui.Dialog.showModal(Dialog.java:1138)
at com.codename1.ui.Dialog.show(Dialog.java:582)
at com.codename1.ui.Dialog.showPopupDialog(Dialog.java:1287)
at com.codename1.ui.Dialog.showPopupDialog(Dialog.java:1154)
Either you're passing a parameter that's null, or you are trying to call a method on an object that is null.
So the simplest way of finding out which is null, is doing this:
System.out.println("myObject = "+myObject);
for every object that you're using near the nullpointer exception until you find something that's null.
This is a regression due to the fix for this issue. We fixed it and it will be available in the next update.
I'm guessing you have a style for PopupDialog in your theme. I suggest removing it as a workaround.
That is the best way in which I can describe what's going on.
This is my line of code:
if (offer.getFamily().getProfileImage() == null)
And this is what the debugger is showing:
Both offer and family aren't null.
So instead of going inside the if like it should it tries to get the file path and of course it fails with a NullPointerException.
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.isEmpty()' on a null object reference
at java.io.UnixFileSystem.resolve(UnixFileSystem.java:95)
at java.io.UnixFileSystem.resolve(UnixFileSystem.java:130)
at java.io.File.getAbsolutePath(File.java:524)
at com.yournanny.utilities.ProfileImageUtilities.showProfileImage(ProfileImageUtilities.java:109)
Here is where I get the error:
public static void showProfileImage(User user, ImageView image) {
image.setImageBitmap(BitmapFactory.decodeFile(user.getProfileImage().getAbsolutePath()));
}
What is going on here?
Update
Looking at the comments I broke the chains and re-run it, neither offer or getFamily() return null, if I call other method over them I get the expected values.
But getProfileImage() is definitely returning null, the problem is that somehow it isn't null enough when I compare it in the if.
But on calling getProfileImage().getAbsolutePath() I get this:
Well apparently the problem was with the deserialization of the offer (and particularly of the family inside of it).
I was getting offer through a retrofit get call.
I added transient to the profileImage attribute and this fixed the problem:
private transient File profileImage;
Now this is what the debugger shows:
So I'm guessing gson (I'm using it to deserialize the retrofit responses) was creating a file without a assigning it a path and that's why it was and wasn't null.
But a proper explanation would be great.
The File was non-null but its name was null internally.
I am using wikidata api to fetch a entity using its english title,
wdf = WikibaseDataFetcher.getWikidataDataFetcher();
eid = wdf.getEntityDocumentsByTitle("enwiki", entitle);
Earlier, with an older version of wikidata-api, I was able to run it smoothly.
After updating to version 5.0.0, I always get the following error,
Exception in thread "main" java.lang.NullPointerException
at org.wikidata.wdtk.wikibaseapi.ApiConnection.fillCookies(ApiConnection.java:544)
at org.wikidata.wdtk.wikibaseapi.ApiConnection.sendRequest(ApiConnection.java:346)
at org.wikidata.wdtk.wikibaseapi.WbGetEntitiesAction.wbGetEntities(WbGetEntitiesAction.java:187)
How to fix this?
I get the same problem.
I tried to use latest version from github and get the same exception.
I execute the sample from documentation i.e the simple call:
Map<String, EntityDocument> results = wbdf.getEntityDocuments("Q80", "P31");
Seems code doesn't check for existence of a given cookie.
I added the verification, recompiled and everything seems to work.
Go to ApiConnection.java:543
if (headerCookies != null)
for (String cookie : headerCookies) {
No warranty ! :-)
I have to interface a third party COM API into an Java application. So I decided to use Com4j, and so far I've been satisfied, but now I've run into a problem.
After running the tlbgen I have an object called IAddressCollection which according to the original API documentation conforms to the IEnum interface definition. The object provides an iterator() function that returns a java.util.Iterator<Com4jObject>. The object comes from another object called IMessage when I want to find all the addresses for the message. So I would expect the code to work like this:
IAddressCollection adrCol = IMessage.getAddressees();
Iterator<Com4jObject> adrItr = adrCol.iterator();
while(adrItr.hasNext()){
Com4jObject adrC4j = adrItr.next();
// normally here I would handle the queryInterface
// and work with the rest of the API
}
My problem is that when I attempt the adrItr.next() nothing happens, the code stops working but hangs. No exception is thrown and I usually have to kill it through the task manager. So I'm wondering is this a problem that is common with Com4j, or am I handling this wrong, or is it possibly a problem with the API?
Ok, I hate answering my own question but in this case I found the problem. The issue was the underlying API. The IAddressCollection uses a 1 based indexing instead of a 0 based as I would have expected. It didn't provide this information in the API documentation. There is an item function where I can pull the object this way and so I can handle this with
IAddressCollection adrCol = IMessage.getAddressees();
for(int i = 1; i <= adrCol.count(); i++){
IAddress adr = adrCol.item(i);
// IAddress is the actual interface that I wanted and this works
}
So sorry for the annoyance on this.