gpt4 book ai didi

java - Android 中使用 GoogleAPI 进行音译

转载 作者:行者123 更新时间:2023-12-01 14:34:51 25 4
gpt4 key购买 nike

需要帮助..!我正在研究 Android Transliteration,我的代码中出现以下 3 个错误。

1)GoogleAPI cannot be resolved

2)Translate cannot be resolved

3)Language cannot be resolved

我已经正确导入了所有必需的包,并且还添加了所需的外部 jar 文件。但无法知道我到底错在哪里.. 以下是我的代码 fragment -->

public class MainActivity extends Activity 
{
EditText myInputText;
Button myTranslateButton;
TextView myOutputText;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myInputText = (EditText)findViewById(R.id.inputText);
myTranslateButton = (Button)findViewById(R.id.translateButton);
myOutputText = (TextView)findViewById(R.id.outputText);
myTranslateButton.setOnClickListener(MyTranslateButtonOnClickListener);
}

private Button.OnClickListener MyTranslateButtonOnClickListener
= new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
String InputString;
String OutputString = null;
InputString = myInputText.getText().toString();

try
{
GoogleAPI.setHttpReferrer("http:\\www.google.com");
GoogleAPI.setKey("API_KEY");
OutputString = Translate.DEFAULT.execute(InputString,Language.ENGLISH, Language.HINDI);
}
catch (Exception ex)
{
ex.printStackTrace();
OutputString = "Error";
}
Typeface customF = Typeface.createFromAsset(getAssets(), "akshar.ttf");
//final TextView textV = (TextView) findViewById(...);
myOutputText.setTypeface(customF);
myOutputText.setText(OutputString);
}

};
}

For your better understanding please have a look on following screenshots

导入 Image-1 包Image-2 包含错误的代码Image-3 我的构建配置

Packages Imported

Code that Contains Error

My Build Configuration

请帮忙...谢谢...!!

最佳答案

导入这两个:

import com.google.api.translate.Language;
import com.google.api.translate.Translate;

&我认为如果将翻译作为单独的方法使用会更好。检查 this出去。

关于java - Android 中使用 GoogleAPI 进行音译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16581391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com