[英]Unable to load the web View Android Studios
There is an error in the webview part. webview部分有错误。 Please help me out.
请帮帮我。 Following the tutorial here I have set up an app that should be able to open a URL and place it into an WebView.
按照此处的教程,我已经设置了一个应用程序,该应用程序应该能够打开URL并将其放入WebView。 The only issue is that the app stops while running in emulator.
唯一的问题是,应用程序在模拟器中运行时会停止。
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import info.androidhive.materialdesign.R;
`enter code here`public class WebViewActivity1 extends AppCompatActivity {
WebView wv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view1);
wv1=(WebView)findViewById(R.id.webView);
WebSettings webSettings = wv1.getSettings();
webSettings.setJavaScriptEnabled(true);
wv1.loadUrl("http://www.medplusmart.com/");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_web_view_activity1, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
First - In your question please provide to developers your logCat. 首先 -在您的问题中,请向开发人员提供您的logCat。
Second - you have bug in your code look at this image why there is 'enter here your code'
其次 -您的代码中有错误请看这张图为什么会有
'enter here your code'
before public class WebViewActivity1 extends AppCompatActivity
前
public class WebViewActivity1 extends AppCompatActivity
hope it's help :) 希望对您有所帮助:)
Make sure that you have declared required permissions in your manifest file 确保您已在清单文件中声明了必需的权限
[your-proj\app\src\main\AndroidManifest.xml]:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your-package">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
...
<activity android:name=".WebViewActivity1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.