简体   繁体   English

检查BitmapDescriptor是否为null

[英]Check BitmapDescriptor for null

I want to check BitmapDescriptor for null. 我想检查BitmapDescriptor是否为null。

The documentation for BitmapDescriptorFactory.fromAsset states that: BitmapDescriptorFactory.fromAsset的文档指出:

Returns the BitmapDescriptor that was loaded from the asset or null if failed to load. 返回从资源加载的BitmapDescriptor,如果加载失败,则返回null。

    BitmapDescriptor bd = BitmapDescriptorFactory.fromAsset("markerimages/filename.png");
    if (bd == null) {
        // doSomething...
    }

Despite this, I am unable to catch BitMapDescriptor in a null state - even when I pass a filename that does not exist, the fromAsset method does not return a null. 尽管如此,我无法在空状态下捕获BitMapDescriptor - 即使我传递了一个不存在的文件名,fromAsset方法也不会返回null。

It may be that the fromAsset method doesn't return null, but perhaps returns the same as defaultMarker() returns. 可能是fromAsset方法不返回null,但可能返回与defaultMarker()返回相同的方法。 (ie the documentation is wrong) (即文件错了)

I'd check whether the value you get for a (presumably non-existent) asset is either '==' or .Equals the defaultMarker(). 我会检查你得到的(可能是不存在的)资产的值是'=='还是.Equals是defaultMarker()。 That could be how you detect a non-existent asset. 这可能是您检测不存在的资产的方式。

I have found, contrary to documentation, BitmapDescriptorFactory.fromAsset(String) does not return null if the specified asset does not exist. 我发现,与文档相反,如果指定的资产不存在,BitmapDescriptorFactory.fromAsset(String)不会返回null。 I am currently implementing a work around where I pre-load the list of assets which do exist using AssetManager.list(""). 我目前正在实现一个工作,我预先加载使用AssetManager.list(“”)存在的资产列表。 Then, for an asset name in question I search the cached list of assets to determine whether the specified asset exists or not. 然后,对于有问题的资产名称,我搜索缓存的资产列表以确定指定的资产是否存在。

This was the least resource intensive approach I could thnk of since I could not depend on a null return when the asset did not exist. 这是我可以解决的资源最少的方法,因为当资产不存在时我不能依赖于null返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM