在java中,使用android-19,这很好用:
import android.speech.tts.TextToSpeech.Engine;
但是在斯卡拉:
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)
}
答案 0 :(得分:1)
不幸的是,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)
}