2016-05-04 18 views
0

私はアンドロイドSDKのチュートリアルhereに従っています。サービスリスナーを設定すると、ビルド時にエラーが発生します。Androidライブラリ実装の問題

エラーとコード(OnCreateの下MainActivity内側):

aiService = AIService.getService(this, config); 
    aiService.setListener(this); 

がエラー:

Error: method setListener in class AIService cannot be applied to given types; 
required: AIListener 
found: MainActivity 
reason: actual argument MainActivity cannot be converted to AIListener by method invocation conversion 
私はここに、クラスに実装しました

public class MainActivity extends AppCompatActivity implements AIListener { 

AIListenerクラス

public interface AIListener { 
void onResult(AIResponse result); // here process response 
void onError(AIError error); // here process error 
void onAudioLevel(float level); // callback for sound level visualization 
void onListeningStarted(); // indicate start listening here 
void onListeningCanceled(); // indicate stop listening here 
void onListeningFinished(); // indicate stop listening here 
} 

AIListenerはMainActivityによって正しく実装されていますが、MainActivityでこれらのメソッドをオーバーライドしていても、Androidスタジオではメソッドが使用されていないことが表示されます。

enter image description here

答えて

0

と活動への参照を渡しているとして、それは私が実装を切り替えないことを示し自分自身のクラスを実装するのではなく、ai.api.AIListenerに渡します。これは、チュートリアルで教えてくれることなので、混乱しています。たぶん古いですね!

0

あなたの活動は、インタフェースAIListenerを実装する必要があります、現在のエラーは、ライン

aiService.setListener(this); 
+0

私は自分の質問を編集しましたが、私はそれを実装しました。だから、これはとても混乱しています! –

+0

AIListenerは別ファイルですが、これはすべてMainActivityの下にあります。 –

+0

私は間違ったエラーを打ちました。それは問題で修正されました。 –