throw with null exception

0 投票

产品 imobile for android  10.0.1 操作系统 android

数据类型 文件型

问题详细描述:

在给 MapControl 设置手势侦听器 GestureDetector,获取到点击时的点坐标,构建了一个矩形,使用 

DatasetVector.query() 进行查询,在查询得到数据集记录后,遍历数据集获取图形时抛出的异常。

Geometry geometry = recordset.getGeometry()

在不开启混淆时没有异常,在开启混淆之后就有异常了。

查询的代码如下:


    protected void singleTapUp(MotionEvent event, Point2D point2D){
        //可查询的路线图层
        String[] stringArray = getResources().getStringArray(R.array.map_lx);
        Map map = mapControl.getMap();
        //当前地图可视比例尺
        double scale = map.getScale();

        //查询范围 size个像素
        int size = 32;
        Point point = new Point((int) event.getX(), (int) event.getY());
        Point lt = new Point(point.getX() - size, point.getY() - size);
        Point rb = new Point(point.getX() + size, point.getY() + size);

        Point2D ltPoint2D = map.pixelToMap(lt);
        Point2D rbPoint2D = map.pixelToMap(rb);
        Rectangle2D rectangle2D = new Rectangle2D(ltPoint2D, rbPoint2D);
        double v = rectangle2D.getWidth() / 2;

        //显示出来那个点
        GeoPoint geoPoint = new GeoPoint(point2D);
        showDebugPoint(point2D);
        int num = 0;
        for (String layerName : stringArray) {
            Layer layer = map.getLayers().get(layerName);
            if (null == layer) continue;
            //是否在可视范围
            double minVisibleScale = layer.getMinVisibleScale();
            if (minVisibleScale > scale) continue;

            DatasetVector vector = (DatasetVector) layer.getDataset();
            Recordset query = vector.query(geoPoint, v, CursorType.STATIC);
            if (query == null) continue;
            Log.i(TAG, "singleTapUp: count ->"+query.getRecordCount()+" in "+layerName);
            if (query.getRecordCount() == 0) {
                query.dispose();
                continue;
            }
            num+=query.getRecordCount();
            if (query.moveFirst()) {
                do {
                    //在这一步出现的问题
                    Geometry geometry = query.getGeometry();
                    if (geometry==null) continue;
                    //查看是什么类型的
                    GeometryType type = geometry.getType();
                    Log.i(TAG, "singleTapUp: type-> "+type.name());
                } while (query.moveNext());

            }
            query.dispose();
        }

        if (num>0){
            Toast.makeText(MapActivity.this,String.valueOf(num),Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(MapActivity.this,"没有选中",Toast.LENGTH_SHORT).show();
        }
    }

给 MapControl 设置 手势侦听

    private GestureDetector.SimpleOnGestureListener simpleOnGestureListener = new GestureDetector.SimpleOnGestureListener(){
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            Point2D point2D = mapControl.getMap().pixelToMap(new Point((int) e.getX(), (int) e.getY()));
            singleTapUp(e,point2D);
            return true;
        }
    };



//设置
  mapControl.setGestureDetector(new GestureDetector(MapActivity.this,simpleOnGestureListener));

Proguard 规则


# 自身
-keep class com.example.supermapquestion.**{*;}
# 不混淆超图包
-keep class com.supermap.**{*;}

build.gradle


    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug{
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

异常堆栈信息如下:

07-31 09:24:34.787 10989-10989/com.example.supermapquestion E/InputEventReceiver: Exception dispatching input event.
07-31 09:24:34.787 10989-10989/com.example.supermapquestion E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
07-31 09:24:34.797 10989-10989/com.example.supermapquestion E/MessageQueue-JNI: java.lang.NullPointerException: throw with null exception
        at com.supermap.data.Geometry.createInstance2()
        at com.supermap.data.Recordset.getGeometry(:957)
        at com.example.supermapquestion.map.MapActivity.singleTapUp(:164)
        at com.example.supermapquestion.map.MapActivity$3.onSingleTapUp(:119)
        at android.view.GestureDetector.onTouchEvent(GestureDetector.java:638)
        at com.supermap.mapping.MapControl2.onMultiTouch(:1384)
        at com.supermap.mapping.MapControl2.onTouchEvent(:1301)
        at android.view.View.dispatchTouchEvent(View.java:9390)684)

7月 31, 2020 分类:  311次浏览 | 用户: mxc 牛刀小试 (108 分)

1个回答

0 投票
 
已采纳
您好,我们的包是经过混淆了的,建议不再混淆我们的包。
7月 31, 2020 用户: 董懿鑫 登峰造极 (7,405 分)
采纳于 7月 31, 2020 用户:mxc
你好,怎么不混淆你们的包?

不混淆超图的包 
 

# 不混淆超图包
-keep class com.supermap.**{*;}

问题解决了,是 gradle 不兼容的问题。将 gradle 版本改为 4.6;插件版本改为 3.2.0 之后就好了。
 

    dependencies {
//        classpath "com.android.tools.build:gradle:4.0.1"
        classpath "com.android.tools.build:gradle:3.2.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

gradle 版本

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

...