尝试在空对象引用上调用虚方法'void com.phonegap.CallbackServer.sendJavascript(java.lang.String)'

时间:2016-11-25 06:06:46

标签: java android cordova nullpointerexception

我无法弄清问题是什么。谁能请帮忙。我正在使用phonegap 1.3.0.jar开发phonegap应用程序。 Logcat在那时显示错误。

以下是代码:

public class Main extends DroidGap {

    ConnectivityManager connectivity;
    NetworkInfo activeNetwork;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setIntegerProperty("splashscreen", R.drawable.splash);

        connectivity  = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        activeNetwork = connectivity.getActiveNetworkInfo(); 

        if(activeNetwork != null) {
            if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
            {Toast.makeText(this,activeNetwork.getTypeName(), Toast.LENGTH_SHORT).show();
            super.loadUrl("url", 1000);}

            else if(activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) 
            {Toast.makeText(this, activeNetwork.getTypeName(), Toast.LENGTH_SHORT).show();
            super.loadUrl("url", 1000);}    
        }//Connected to the Internet

        else {
            super.loadUrl("file:///android_asset/www/index.html", 1000);}       
        //No Internet Connection
    }

     public void onReceivedError( int errorCode, String description, String failingUrl)
        {
            super.loadUrl("file:///android_asset/www/index.html", 1000);
        //Server down.  
        }
}

和logcat错误:

--------- beginning of crash
11-25 10:27:13.000  9934  9934 E AndroidRuntime: FATAL EXCEPTION: main
11-25 10:27:13.000  9934  9934 E AndroidRuntime: Process: com.app.tradelance, PID: 9934
11-25 10:27:13.000  9934  9934 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.phonegap.CallbackServer.sendJavascript(java.lang.String)' on a null object reference
11-25 10:27:13.000  9934  9934 E AndroidRuntime:    at com.phonegap.DroidGap$LinearLayoutSoftKeyboardDetect.onMeasure(DroidGap.java:1699)
11-25 10:27:13.000  9934  9934 E AndroidRuntime:    at android.view.View.measure(View.java:18794)

0 个答案:

没有答案