java.lang.NullPointerException当尝试在类中调用setContentView来扩展MainActivity时

时间:2016-11-17 21:25:33

标签: android

抱歉我的英语不好,这就是交易,我正在努力使用ZXingScanner Library调整QR码扫描器,但我有这个问题。

    java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference

first of all, send the context to the second one which extends to Mainactivity.

Mainactivity

//cast floatingbutton


  FloatingButton = (FloatingActionButton) findViewById(R.id.A1);
    View.OnClickListener l = new Eventoqr(this);
    FloatingButton.setOnClickListener(l);

Eventoqr  class

    public class Eventoqr extends MainActivity implements View.OnClickListener, ZXingScannerView.ResultHandler

//method that implements start camera

public void QRscan(View vista)
{
    Log.e("Inicio de camara", cntx.toString());
    MyscannerView = new ZXingScannerView(cntx);
    setContentView(MyscannerView); /* Error generates here
}

I hope someone can help me whit this, thanks any way.

1 个答案:

答案 0 :(得分:0)

显然,您的android.view.Windownull,您是否可以在代码中提供此调用?