0

我正在为 gamemaker studio 制作文本到语音的 android 扩展,我收到此错误:05-01 17:16:41.304 16939 17013 I yoyo : Can't find argfree method on extension class:getMic [] 尝试时在游戏中使用我的扩展程序。游戏不会崩溃,只是在扩展中找不到任何东西。那么究竟什么是 argfree 方法呢?

我还尝试将 onCreate 方法更改为公共方法并从 GM:S 和其他一些东西调用它,但没有运气。这是相关代码,如果您需要更多信息,请询问。

java类TtsStt:

       protected void onCreate(Bundle savedInstanceState) { //HERE is where I tried replacing
//protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); 
//with just public void initTTS() {...} but got same error   
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tts_stt);
    preferences = getSharedPreferences(PREFS,0);
    editor = preferences.edit();
    editor.putString(TSTYLE, "military time").apply();
    RunnerActivity.CurrentActivity.findViewById(R.id.microphoneButton).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            listen();
        }
    });
    loadQuestions();
    tts = new TextToSpeech(RunnerActivity.CurrentActivity, new TextToSpeech.OnInitListener() { 
    @Override
        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {
                int result = tts.setLanguage(Locale.US);
                if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                    Log.i("yoyo", "This Language is not supported");
                }
                speak("Hello");
            } else {
                Log.i("yoyo", "Initilization Failed!");
            }
        }
    });
}
public void getMic() {
            listen(); 
} 


private void listen(){
    Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say something");
    try {
        RunnerActivity.CurrentActivity.startActivityForResult(i, 100);
    } catch (ActivityNotFoundException a) {
      Log.i("yoyo", "Your device doesn't support Speech Recognition");
    }
}

在活动级别在我的清单中,我注入了这个:

<activity android:name="${YYAndroidPackageName}.TtsStt" 
android:theme="@style/Theme.AppCompat.NoActionBar"
android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
            <category android:name="android.intent.category.LAUNCHER" />
        />
    />

并在清单中注入 gradle 依赖项:

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
4

1 回答 1

0

那么答案是非常出乎意料的,当在gamemaker studio和android java之间使用代码扩展时,如果你需要使用onCreate方法,你不能写protected void onCreate(..)相反你必须使用public void onCreate( ...... ) 这与 Java 中的正常和预期相反,我只是通过阅读一篇关于为什么 onCreate 始终受到保护的帖子才明白这一点,并看到有人回应说没有理由不这样做,所以我做了其他事情,它奏效了!

于 2017-05-02T13:34:46.580 回答