无法使用SplashScreen和WebView启动应用程序

时间:2015-07-26 15:44:46

标签: java android android-activity splash-screen splash

无法运行我的Android应用https://github.com/iSCApps/isc.apps.android.videofy

  

我创建了 Splash.java MainActivity.java

Splash.java:

package isc.apps.android.videofy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class Splash extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);

        final Handler handel = new Handler();
        handel.postDelayed(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            Intent loadSplash = new Intent(Splash.this, MainActivity.class);

                startActivity(loadSplash);

                finish();
            }
        }, 5000);
    }
}

MainActivity.java:

package isc.apps.android.videofy;

    import android.os.Bundle;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.ProgressDialog;
    import android.util.Log;
    import android.view.Menu;
    import android.view.Window;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.Toast;

public class MainActivity extends Activity {

private WebView webView;
private ProgressDialog progressBar;
private static final String TAG = "Main";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

    webView = (WebView) findViewById(R.id.trnity);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setBuiltInZoomControls(true);
    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    progressBar = new ProgressDialog(MainActivity.this);
    progressBar.setMessage("Trinity tuts loading...");
    progressBar.setCancelable(false);
    progressBar.setCanceledOnTouchOutside(false);
    progressBar.show();
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.i(TAG, "Loading");
            view.loadUrl(url);
            return true;
        }

        public void onPageFinished(WebView view, String url) {
            Log.i(TAG, "Done loading " + url);
            if (progressBar.isShowing()) {
                progressBar.dismiss();
            }
        }

        public void onReceivedError(WebView view, int errorCode,
                                    String description, String failingUrl) {
            Log.e(TAG, "Error: " + description);
            Toast.makeText(getApplicationContext(),
                    "Oh no! " + description, Toast.LENGTH_SHORT).show();
            alertDialog.setTitle("Error");
            alertDialog.setMessage(description);
            alertDialog.setCancelable(false);
            alertDialog.show();

        }
    });
    webView.loadUrl("https://isc-host.github.io/videos.isc");

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}
  

该应用程序一直在我的Android 4.0.3上崩溃。

我还在Android Studio上的Nexus S模拟器上运行adb logcat

- waiting for device -
error: protocol fault (status read)
  

您知道代码错误在哪里吗?

1 个答案:

答案 0 :(得分:1)

错误可能来自这一行:

 webView = (WebView) findViewById(R.id.trnity);

在activity_main中,webView的id是视频,在代码中是它的连续性。