1
我有類此代碼A
嘗試調用接口方法的Android
private RtcListener mListener;
@Override
public void Update(String string) {
//here its work now i want to pass data to Interface
mListener.onUpdate(sometext);
}
public interface RtcListener{
void onUpdate(String string);
}
現在
在另一個類及其B
我實現接口
public class B extends Service implements A.RtcListener{
// here i Override interface method
@Override
public void onUpdate(String string) {
Log.d("dwdwadwadwd"," the data is"+string);
}
}
其給我錯誤
Attempt to invoke interface method 'void ..... on a null object reference
@quidproquo多數民衆贊成在回答工作,活動和服務不帶班沒有活動 – medo
這不是你如何通常會與服務通信,您應該使用LocalBroadcastManager或EventBus。 – Egor
Your mListener爲空 –