"Unfortunately, has stopped" eclipse android avd - android

In the eclipse/android AVD, I get "Unfortunately, has stopped"
Help please.. here is the code
I just follow the other codes...
I tried everything I can I just don't know
what to do ...
help help help... not a total programmer ...
package com.somedomain.animatedinteractive;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
#SuppressLint("SetJavaScriptEnabled")
#SuppressWarnings("deprecation" )
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.action_settings);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.loadUrl("file:///android_asset/Parable_Book.swf");
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setBackgroundColor(Color.parseColor("#000000"));
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

Your main layout does not have a WebView with id action_settings. Change
mWebView = (WebView) findViewById(R.id.action_settings);
to
mWebView = (WebView) findViewById(R.id.webview);
Also, when getting an "unfortunately app has stopped" message, it's a good idea to have a look at the exception stacktrace in logcat. Include it in your question, too.

package com.somedomain.animatedinteractive;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
#SuppressLint("SetJavaScriptEnabled")
#SuppressWarnings("deprecation" )
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.loadUrl("file:///android_asset/Parable_Book.swf");
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setBackgroundColor(Color.parseColor("#000000"));
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

Related

How to use webView in read mode kotlin?

I have an app and i want to open the URL with Reading Mode
Without ads or something the reader don't need to see
How can i do that haw can i enable the reading mode on in kotlin ?
Try it with WebView,
In .xml file add this code:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
And inside activity(or fragment)
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
}
}

WebView example android

There is a error in mView, I need solution
package com.example.account;
import android.app.Activity;
import android.os.Bundle;
public class WebView extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
}
}
My xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Cannot cast from view to webview
WebView mView = (WebView) findViewById(R.id.webView1)
Try this layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
give me feedback on this.
Update:
You should change your Activity name with Different one. or defined your WebView with different name like:
WebView mView2 = (WebView) findViewById(R.id.webView1)
You are using your activity name as WebView. This name is already used by SDK API. This is the reason it is giving you error.
To solve it, just rename your WebView.java file to some another name like MyWebView.java then your problem will surely solve.
To safely rename your .java file, Just go to packageexplorer , select WebView.java and press F2, and give new name.
Try this, it may help
1 . Using Eclipse, create a new Android project and name it as WebView.
2 . Add the following statements to the main.xml file:
<?xml​ version=”1.0” ​encoding=”utf-8”?>
<LinearLayout ​xmlns:android=”http://schemas.android.com/apk/res/android” ​​​​android:orientation=”vertical” ​​​​
android:layout_width=”fill_parent” ​
​​​android:layout_height=”fill_parent” ​​​​>
<WebView
android:id=”#+id/webview1” ​​
​​android:layout_width=”wrap_content” ​
​​​android:layout_height=”wrap_content” />
</LinearLayout>
3 . In the MainActivity.java file, add the following statements in bold:
package​ com.emergingandroidtech.WebView;
import​ android.app.Activity;
import ​android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public ​class ​MainActivity​ extends​ Activity
​{
​​​​
/**​Called​ when​ the ​activity ​is ​first ​created.​*/
​#Override ​​
​​public ​void ​onCreate(Bundle​savedInstanceState)​
{
​​​​​​​​super.onCreate(savedInstanceState);
​setContentView(R.layout.main);
​​​​​​​​
WebView wv = (WebView) findViewById(R.id.webview1);
​​​​​​​​WebSettings webSettings = wv.getSettings(); ​​
​​​​​​webSettings.setBuiltInZoomControls(true);
​​​​​​​​wv.loadUrl( ​​​​​​​​“www.google.com”);
​​​​}
}
4. Don't forget to give the internet permission in manifest file
Thank you
You should keep webview inside any parent view
Do not use reserved words as your variable, class and method name.
Here, WebView is reserved or already used by SDK. If you use that word again, Compiler will get confused.
activity_main.xml
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity
{
private WebView webview;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview=(WebView)findViewById(R.id.webview);
//loads androidride homepage to webview
webview.loadUrl("https://www.androidride.com");
}
}

How can I hide the URL bar from an Android browser

I want to hide the URL bar from the browser permanently, and it should not appear even if the person gets redirected from one page to another.
Here is my .java code:
package com.example.com.android.royalcastleapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.support.v4.app.NavUtils;
public class Bookinghome extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bookinghome);
//Get a reference of WebView holder
WebView webview = (WebView) this.findViewById(R.id.webview);
//Get the settings
WebSettings websettings = webview.getSettings();
//Enable Javascript
websettings.setJavaScriptEnabled(true);
//Make the zoom controls visible
websettings.setBuiltInZoomControls(true);
//Load the default url.
webview.loadUrl("http//okRoom.aspx");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_bookinghome, menu);
return true;
}
}
And here is my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="#dimen/padding_medium"
android:text="#string/hello_world"
tools:context=".Bookinghome"
android:id= "#+id/webview"/>
</RelativeLayout>
If anyone could suggest any changes I could make, that would be great!
Your application starts default browser.
You need to use WebViewClient.shouldOverrideUrlLoading like described here: https://stackoverflow.com/a/2379054/2183804

How can we display html page lying in assets?

my code is Here
java file
package org.example.webviewdemo;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewDemo extends Activity {
private WebView webView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webview_compontent);
webView.loadUrl("file://android_asset//faq.htm");
}
}
xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="#+id/webview_compontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
/>
but i cant get page content
faq.htm is in folder assets
please helpme
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/folderName/index.html");
Have you tried using Uri.fromFile( File ), and get the file from getAssets().open(fileName)??

Changing the background of webview in android

I am developing an android game application,I have implemented all the screens.Now i want to change the webview background color,Can anybody guide me.Here is my xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
<WebView
android:id="#+id/webbrowser"
android:layout_width="fill_parent"
android:layout_height="345px"
android:layout_marginTop="46px"/>
<Button
android:id="#+id/Btn"
android:background="#drawable/back_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="109px"
android:layout_marginTop="37px">
</Button>
</LinearLayout>
And My Java file is
package com.tli.roadtripbingo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
public class WebView1 extends Activity {
private Button Back;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.webview);
Back = (Button)findViewById(R.id.back);
WebView webView = (WebView) findViewById(R.id.webbrowser);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.vikingredning.no/skilt.aspx");
webView.setWebViewClient(new HelloWebViewClient());
}
class HelloWebViewClient extends WebViewClient
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
};
}
Thanks in advance
Regards
Tushar
You can find answer here Change Background color and font color
WebView myWebView = (WebView) findViewById(R.id.myWebView);
myWebView.setBackgroundColor(Color.parseColor("#123456"));
You can make the WebView transparent like this:
WebView webView = (WebView) findViewById(R.id.webView);
webView.setBackgroundColor(Color.TRANSPARENT);
<LinearLayout
android:id="#+id/web_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/web_bg_color"
android:gravity="center" >
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.setBackgroundColor(Color.TRANSPARENT);
mWebView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
It worked for me in lollipop also.
try it once!
You may also want to reload the page after changing colors by using the reload() method:
webView.reload();

Categories

Resources