【问题标题】:Cannot resolve Base64.encodeToString无法解析 Base64.encodeToString
【发布时间】:2016-05-07 09:11:30
【问题描述】:

我正在尝试使用以下代码将图像保存在 firebase 上。

  Bitmap bm = BitmapFactory.decodeFile(imgDecodableString);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  bm.compress(Bitmap.CompressFormat.JPEG,100,baos);
  byte[] byteArray =  baos.toByteArray();
  String encodedImage = Base64.encodeToString(byteArray,Base64.DEFAULT);

但我遇到了一个错误:

cannot resolve method 'encodeToString(byte[],?)' 
cannot resolve symbol 'DEFAULT'

如何解决此错误。

【问题讨论】:

  • 您导入了错误的Base64 类。应该是android.util.Base64,而不是org.apache.commons.codec.binary.Base64
  • 你的问题解决了吗??
  • 现在我开始工作了。我导入了错误的类。
  • 什么是正确的答案然后面临同样的问题
  • Yogesh Borhade,现在不需要使用 base64 字符串,现在 firebase 推出了非常简单有效的解决方案来保存图像和多媒体文件名称 Firebase Storage 请转到 firebase.google.com 并查看文档部分.希望您的问题能得到解决。

标签: android firebase firebase-realtime-database


【解决方案1】:

我认为您的文件中有 import org.apache.commons.codec.binary.Base64,请重新检查并尝试使用 import android.util.Base64。它将解决您的问题 cannot resolve method 'encodeToString(byte[],?)'

【讨论】:

  • 是的,现在它工作正常。您是否知道如何使用 Firebase 列表适配器中的 getter 方法检索图像。
【解决方案2】:

试试看:

val encodedImage = encodeToString(b, DEFAULT)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-08
    • 1970-01-01
    相关资源
    最近更新 更多