在 java 中,使用 android-19,这工作正常:
import android.speech.tts.TextToSpeech.Engine;
但是在 Scala 中:
import android.speech.tts.TextToSpeech.Engine
^
error: value Engine is not a member of object android.speech.tts.TextToSpeech
这很奇怪,因为我可以毫无问题地导入 EngineInfo
,但它不识别类 Engine
,尽管它显然在 android.jar 中
任何修复或解决方法?这是一个scala问题吗?我正在使用 AndroidProguardScala v51 和 Scala IDE 3.0.1 版在 Eclipse 3.7 上进行开发
编辑
例如,我使用它的上下文如下:
if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
mTts = new TextToSpeech(this, mTtsListener)
}
最佳答案
不幸的是,TextToSpeech.Engine
被声明为非静态的,这意味着是这样的:
public class TextToSpeech {
public class Engine {
// ...
}
// ...
}
所以根据this ,您无法访问它。这是我使用包装器的解决方法:
object ConstantsWrapper {
private val cls = classOf[TextToSpeech#Engine]
def apply(fieldName: String) = cls.getDeclaredField(fieldName).get(null)
.toString
val CHECK_VOICE_DATA_PASS = apply("CHECK_VOICE_DATA_PASS")
// Insert more here
}
if (resultCode == ConstantsWrapper.CHECK_VOICE_DATA_PASS) {
mTts = new TextToSpeech(this, mTtsListener)
}
关于java - 值引擎不是对象 android.speech.tts.TextToSpeech 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23495442/