I have this code:
@Override
public void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
InetAddress ip;
mWebview = new WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
String ipv4add;
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
ip = InetAddress.getLocalHost();
ipv4add = ip.getHostAddress().toString();
System.out.println(ipv4add);
mWebview .loadUrl(ipv4add+"/Lab4/Task1/index.php");
mWebview.getSettings().setLoadsImagesAutomatically(true);
mWebview.getSettings().setJavaScriptEnabled(true);
mWebview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
setContentView(mWebview );
} catch (UnknownHostException e) {
e.printStackTrace();
}
So what it does exactly is first: it should get the server ip that the phone is supposed to be connected to, then after that it will be inserted into the URL so that the phone can connect to the localserver and access my php files. However, when I launch this into my android phone it just crashes. Why does it do so? Hoping you guys can help me solve this.