Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 旧android设备上ContentValues.keySet()中的NoSuchMethod错误_Java_Android_Nosuchmethoderror_Android Compatibility - Fatal编程技术网

Java 旧android设备上ContentValues.keySet()中的NoSuchMethod错误

Java 旧android设备上ContentValues.keySet()中的NoSuchMethod错误,java,android,nosuchmethoderror,android-compatibility,Java,Android,Nosuchmethoderror,Android Compatibility,我在使用这个函数时遇到了一个奇怪的错误。在新设备和emulator上运行良好,但在旧设备上测试应用程序时会崩溃。。有什么线索吗 public boolean bind(ContentValues values ) throws DatabaseException { if (values == null) throw new DatabaseException("Values is null"); ArrayList<String> colum

我在使用这个函数时遇到了一个奇怪的错误。在新设备和emulator上运行良好,但在旧设备上测试应用程序时会崩溃。。有什么线索吗

   public boolean bind(ContentValues values ) throws DatabaseException {
        if (values == null) throw new DatabaseException("Values is null");

        ArrayList<String> columnNames = this.getColumnNamesArray(AppController.getDBO().getDatabase());
        String currentKey = null;

        try {
            for (String key : values.keySet()) {
                currentKey = key;
                if (columnNames.contains(key)) {
                    if (values.get(key ) == null ) {
                        this._properties.putNull(key);
                    } else if (values.get(key) instanceof String) {
                        this._properties.put(key, values.getAsString(key));
                    } else if (values.get(key) instanceof Integer) {
                        this._properties.put(key, values.getAsInteger(key));
                    } else if (values.get(key) instanceof Boolean) {
                        this._properties.put(key, values.getAsBoolean(key));
                    } else if (values.get(key) instanceof Byte) {
                        this._properties.put(key, values.getAsByte(key));
                    } else if (values.get(key) instanceof Double) {
                        this._properties.put(key, values.getAsDouble(key));
                    } else if (values.get(key) instanceof Float) {
                        this._properties.put(key, values.getAsFloat(key));
                    } else if (values.get(key) instanceof Long) {
                        this._properties.put(key, values.getAsLong(key));
                    } else if (values.get(key) instanceof Short) {
                        this._properties.put(key, values.getAsShort(key));
                    }
                }
            }
        } catch (Exception e) {
            Log.e(AppController.DEBUG_TAG, "Exception raised: " + getClass().getSimpleName(), e);
            throw new DatabaseException(e.toString(),currentKey);
        } catch (NoSuchMethodError error) {
            // Raised in old devices:
            Log.wtf(AppController.ERROR_TAG, error.getMessage());
            return false;
        }

        return true;

    }
我得到的错误是:

E/AndroidRuntime﹕ 致命异常:主 java.lang.NoSuchMethodError:键集

提前谢谢

旧android设备上ContentValues.keySet中的NoSuchMethod错误

这意味着您需要为API<11使用不同的解决方案,因为API 11提供了解决方案。如何使用API 1中提供的

旧android设备上ContentValues.keySet中的NoSuchMethod错误

这意味着您需要为API<11使用不同的解决方案,因为API 11提供了解决方案。如何使用API 1中提供的


API 11中添加了密钥集。你的min SDK版本是什么?因此,min=5,当它在SDK<11的任何设备上运行时,它都会崩溃。当然,当你在运行SDK 5的设备或模拟器上测试时,你知道这一点;我只是厚颜无耻地将min sdk设置为11,顺便说一句,它仍然崩溃。。现在推荐的min sdk是什么?API 11中添加了密钥集。你的min SDK版本是什么?因此,min=5,当它在SDK<11的任何设备上运行时,它都会崩溃。当然,当你在运行SDK 5的设备或模拟器上测试时,你知道这一点;我只是厚颜无耻地将min sdk设置为11,顺便说一句,它仍然崩溃。。现在推荐的min sdk是什么?
// solution for API < 11
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
   for (Entry<String, Object> item : cv.valueSet()) {
      String key = item.getKey(); // getting key
      Object value = item.getValue(); // getting value
      ...
      // do your stuff
   }
}

// solution for API >= 11
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
   // your current solution
}