1

i have this code in class A

 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);

}

now in another class and its B

i implements the Interface

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);

}



}

its give me the error

 Attempt to invoke interface method 'void .....  on a null object reference
medo
  • 479
  • 3
  • 9
  • 24

1 Answers1

0

i solve it by do this in class B

construct the class

A in class B

A myclass = new A(this,another prameter if u have,another prameter if u have);

and in class A on construct function i do this

public A(RtcListener l , other prameter , other prameter){ //construct method //RtcListener  its your interface name
mListener = l;
}

just be sure your code interface like my code above in question also the implements

that's all :)

medo
  • 479
  • 3
  • 9
  • 24