dongyan1974 2016-03-03 08:46
浏览 210

Gomobile Android使用回调

I have an library written using go mobile and it should has only one callback but when trying implement it, I get two additional methods.

@Override
public Seq.Ref ref() {
    return null;
}

@Override
public void call(int i, Seq seq, Seq seq1) {}

Question is, which is right way to implement callback from go on Android Activity?

Right now i have next:

public class MainActivity extends Activity implements implements Mobile.Callback {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_register);
          Mobile.Client client = Mobile.New("192.168.2.1", 9000, this);
          try {
             client.Connect();
          } catch (Exception e) {
             e.printStackTrace();
          }
    }

    @Override
    public void OnMessage(String s) {
       Log.e("GO", s);
    }

    @Override
    public Seq.Ref ref() {
       return null;
    }

    @Override
    public void call(int i, Seq seq, Seq seq1) {

    }
}

Connection is established successfully but on callback to activity i getting:

panic: runtime error: invalid memory address or nil pointer dereference

If someone can help I'll be really appreciate.

  • 写回答

2条回答 默认 最新

  • doubi8512 2016-03-03 14:07
    关注

    What is the Go source you are binding? (The package mobile and Callback interface)

    For passing the Java class that implements Go interface type, see the section "Passing target language objects to Go" of https://godoc.org/golang.org/x/mobile/cmd/gobind

    Basically, the generated Java interface type is not meant to be used directly. Instead, the Java class should extends the generated Java interface's Stub class.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测