error: non-static method setJavaScriptEnabled(boolean) cannot be referenced from a static context
up vote
0
down vote
favorite
i tried to build a web view app from scratch and as i am new to this i was facing error on line 22, as i set websetting.setjavascriptenabled(true); it didnt accept.
error popup
error: non-static method setJavaScriptEnabled(boolean) cannot be referenced from a static context
WebSettings.setJavaScriptEnabled(true);
my project settings is for android Oreo 8.1
package net.jptechsolutions.jptechinvoice;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
public WebView mywebview;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebview=(WebView)findViewById(R.id.webview);
WebSettings webSettings=mywebview.getSettings();
WebSettings.setJavaScriptEnabled(true);
mywebview.loadUrl("https://*********************");
mywebview.setWebChromeClient(new WebChromeClient());
@Override
public void onBackPressed()
if (mywebview.canGoBack())
mywebview.goBack();
else
super.onBackPressed();
android android-webview
add a comment |
up vote
0
down vote
favorite
i tried to build a web view app from scratch and as i am new to this i was facing error on line 22, as i set websetting.setjavascriptenabled(true); it didnt accept.
error popup
error: non-static method setJavaScriptEnabled(boolean) cannot be referenced from a static context
WebSettings.setJavaScriptEnabled(true);
my project settings is for android Oreo 8.1
package net.jptechsolutions.jptechinvoice;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
public WebView mywebview;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebview=(WebView)findViewById(R.id.webview);
WebSettings webSettings=mywebview.getSettings();
WebSettings.setJavaScriptEnabled(true);
mywebview.loadUrl("https://*********************");
mywebview.setWebChromeClient(new WebChromeClient());
@Override
public void onBackPressed()
if (mywebview.canGoBack())
mywebview.goBack();
else
super.onBackPressed();
android android-webview
2
usewebSettings
instead ofWebSettings
– Blackbelt
Nov 8 at 10:27
1
WebSettings
is class name, whilewebSettings
is variable name.setJavaScriptEnabled
is not static, therefore you can't call it from the class name, only from a variable name
– Vladyslav Matviienko
Nov 8 at 10:32
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i tried to build a web view app from scratch and as i am new to this i was facing error on line 22, as i set websetting.setjavascriptenabled(true); it didnt accept.
error popup
error: non-static method setJavaScriptEnabled(boolean) cannot be referenced from a static context
WebSettings.setJavaScriptEnabled(true);
my project settings is for android Oreo 8.1
package net.jptechsolutions.jptechinvoice;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
public WebView mywebview;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebview=(WebView)findViewById(R.id.webview);
WebSettings webSettings=mywebview.getSettings();
WebSettings.setJavaScriptEnabled(true);
mywebview.loadUrl("https://*********************");
mywebview.setWebChromeClient(new WebChromeClient());
@Override
public void onBackPressed()
if (mywebview.canGoBack())
mywebview.goBack();
else
super.onBackPressed();
android android-webview
i tried to build a web view app from scratch and as i am new to this i was facing error on line 22, as i set websetting.setjavascriptenabled(true); it didnt accept.
error popup
error: non-static method setJavaScriptEnabled(boolean) cannot be referenced from a static context
WebSettings.setJavaScriptEnabled(true);
my project settings is for android Oreo 8.1
package net.jptechsolutions.jptechinvoice;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
public WebView mywebview;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebview=(WebView)findViewById(R.id.webview);
WebSettings webSettings=mywebview.getSettings();
WebSettings.setJavaScriptEnabled(true);
mywebview.loadUrl("https://*********************");
mywebview.setWebChromeClient(new WebChromeClient());
@Override
public void onBackPressed()
if (mywebview.canGoBack())
mywebview.goBack();
else
super.onBackPressed();
android android-webview
android android-webview
edited Nov 11 at 12:52
Zoe
10.7k73575
10.7k73575
asked Nov 8 at 10:22
user8140535
92
92
2
usewebSettings
instead ofWebSettings
– Blackbelt
Nov 8 at 10:27
1
WebSettings
is class name, whilewebSettings
is variable name.setJavaScriptEnabled
is not static, therefore you can't call it from the class name, only from a variable name
– Vladyslav Matviienko
Nov 8 at 10:32
add a comment |
2
usewebSettings
instead ofWebSettings
– Blackbelt
Nov 8 at 10:27
1
WebSettings
is class name, whilewebSettings
is variable name.setJavaScriptEnabled
is not static, therefore you can't call it from the class name, only from a variable name
– Vladyslav Matviienko
Nov 8 at 10:32
2
2
use
webSettings
instead of WebSettings
– Blackbelt
Nov 8 at 10:27
use
webSettings
instead of WebSettings
– Blackbelt
Nov 8 at 10:27
1
1
WebSettings
is class name, while webSettings
is variable name. setJavaScriptEnabled
is not static, therefore you can't call it from the class name, only from a variable name– Vladyslav Matviienko
Nov 8 at 10:32
WebSettings
is class name, while webSettings
is variable name. setJavaScriptEnabled
is not static, therefore you can't call it from the class name, only from a variable name– Vladyslav Matviienko
Nov 8 at 10:32
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
Use
webSettings.setJavaScriptEnabled(true);
instead of
WebSettings.setJavaScriptEnabled(true);
You are using Class name with method name. Use the object name defined by you with the method name.
thanks a lot for ur help and what if i wan to download files from the sites that is opened by my app , what should i add or to edit
– user8140535
Nov 8 at 16:42
Try this. mWebView.setDownloadListener(new DownloadListener() public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); );
– muhammed rameez
Nov 9 at 4:26
thank for ur reply ...idk somehow i did it but now i am facing something new ..can u check this out stackoverflow.com/questions/53216795/…
– user8140535
Nov 9 at 4:59
add a comment |
up vote
0
down vote
You call the static function of WebSettings. It should be: webSettings. setJavaScriptEnabled(true);
thank you... it helped me a lot
– user8140535
Nov 8 at 16:42
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Use
webSettings.setJavaScriptEnabled(true);
instead of
WebSettings.setJavaScriptEnabled(true);
You are using Class name with method name. Use the object name defined by you with the method name.
thanks a lot for ur help and what if i wan to download files from the sites that is opened by my app , what should i add or to edit
– user8140535
Nov 8 at 16:42
Try this. mWebView.setDownloadListener(new DownloadListener() public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); );
– muhammed rameez
Nov 9 at 4:26
thank for ur reply ...idk somehow i did it but now i am facing something new ..can u check this out stackoverflow.com/questions/53216795/…
– user8140535
Nov 9 at 4:59
add a comment |
up vote
2
down vote
Use
webSettings.setJavaScriptEnabled(true);
instead of
WebSettings.setJavaScriptEnabled(true);
You are using Class name with method name. Use the object name defined by you with the method name.
thanks a lot for ur help and what if i wan to download files from the sites that is opened by my app , what should i add or to edit
– user8140535
Nov 8 at 16:42
Try this. mWebView.setDownloadListener(new DownloadListener() public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); );
– muhammed rameez
Nov 9 at 4:26
thank for ur reply ...idk somehow i did it but now i am facing something new ..can u check this out stackoverflow.com/questions/53216795/…
– user8140535
Nov 9 at 4:59
add a comment |
up vote
2
down vote
up vote
2
down vote
Use
webSettings.setJavaScriptEnabled(true);
instead of
WebSettings.setJavaScriptEnabled(true);
You are using Class name with method name. Use the object name defined by you with the method name.
Use
webSettings.setJavaScriptEnabled(true);
instead of
WebSettings.setJavaScriptEnabled(true);
You are using Class name with method name. Use the object name defined by you with the method name.
edited Nov 8 at 11:49
Nishil
2258
2258
answered Nov 8 at 10:27
muhammed rameez
417
417
thanks a lot for ur help and what if i wan to download files from the sites that is opened by my app , what should i add or to edit
– user8140535
Nov 8 at 16:42
Try this. mWebView.setDownloadListener(new DownloadListener() public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); );
– muhammed rameez
Nov 9 at 4:26
thank for ur reply ...idk somehow i did it but now i am facing something new ..can u check this out stackoverflow.com/questions/53216795/…
– user8140535
Nov 9 at 4:59
add a comment |
thanks a lot for ur help and what if i wan to download files from the sites that is opened by my app , what should i add or to edit
– user8140535
Nov 8 at 16:42
Try this. mWebView.setDownloadListener(new DownloadListener() public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); );
– muhammed rameez
Nov 9 at 4:26
thank for ur reply ...idk somehow i did it but now i am facing something new ..can u check this out stackoverflow.com/questions/53216795/…
– user8140535
Nov 9 at 4:59
thanks a lot for ur help and what if i wan to download files from the sites that is opened by my app , what should i add or to edit
– user8140535
Nov 8 at 16:42
thanks a lot for ur help and what if i wan to download files from the sites that is opened by my app , what should i add or to edit
– user8140535
Nov 8 at 16:42
Try this. mWebView.setDownloadListener(new DownloadListener() public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); );
– muhammed rameez
Nov 9 at 4:26
Try this. mWebView.setDownloadListener(new DownloadListener() public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); );
– muhammed rameez
Nov 9 at 4:26
thank for ur reply ...idk somehow i did it but now i am facing something new ..can u check this out stackoverflow.com/questions/53216795/…
– user8140535
Nov 9 at 4:59
thank for ur reply ...idk somehow i did it but now i am facing something new ..can u check this out stackoverflow.com/questions/53216795/…
– user8140535
Nov 9 at 4:59
add a comment |
up vote
0
down vote
You call the static function of WebSettings. It should be: webSettings. setJavaScriptEnabled(true);
thank you... it helped me a lot
– user8140535
Nov 8 at 16:42
add a comment |
up vote
0
down vote
You call the static function of WebSettings. It should be: webSettings. setJavaScriptEnabled(true);
thank you... it helped me a lot
– user8140535
Nov 8 at 16:42
add a comment |
up vote
0
down vote
up vote
0
down vote
You call the static function of WebSettings. It should be: webSettings. setJavaScriptEnabled(true);
You call the static function of WebSettings. It should be: webSettings. setJavaScriptEnabled(true);
answered Nov 8 at 10:27
Louis Solo
1162
1162
thank you... it helped me a lot
– user8140535
Nov 8 at 16:42
add a comment |
thank you... it helped me a lot
– user8140535
Nov 8 at 16:42
thank you... it helped me a lot
– user8140535
Nov 8 at 16:42
thank you... it helped me a lot
– user8140535
Nov 8 at 16:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205732%2ferror-non-static-method-setjavascriptenabledboolean-cannot-be-referenced-from%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
use
webSettings
instead ofWebSettings
– Blackbelt
Nov 8 at 10:27
1
WebSettings
is class name, whilewebSettings
is variable name.setJavaScriptEnabled
is not static, therefore you can't call it from the class name, only from a variable name– Vladyslav Matviienko
Nov 8 at 10:32