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();












share|improve this question



















  • 2




    use webSettings instead of WebSettings
    – Blackbelt
    Nov 8 at 10:27






  • 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














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();












share|improve this question



















  • 2




    use webSettings instead of WebSettings
    – Blackbelt
    Nov 8 at 10:27






  • 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












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();












share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 12:52









Zoe

10.7k73575




10.7k73575










asked Nov 8 at 10:22









user8140535

92




92







  • 2




    use webSettings instead of WebSettings
    – Blackbelt
    Nov 8 at 10:27






  • 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












  • 2




    use webSettings instead of WebSettings
    – Blackbelt
    Nov 8 at 10:27






  • 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







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












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.






share|improve this answer






















  • 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

















up vote
0
down vote













You call the static function of WebSettings. It should be: webSettings. setJavaScriptEnabled(true);






share|improve this answer




















  • thank you... it helped me a lot
    – user8140535
    Nov 8 at 16:42










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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

























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.






share|improve this answer






















  • 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














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.






share|improve this answer






















  • 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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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












up vote
0
down vote













You call the static function of WebSettings. It should be: webSettings. setJavaScriptEnabled(true);






share|improve this answer




















  • thank you... it helped me a lot
    – user8140535
    Nov 8 at 16:42














up vote
0
down vote













You call the static function of WebSettings. It should be: webSettings. setJavaScriptEnabled(true);






share|improve this answer




















  • thank you... it helped me a lot
    – user8140535
    Nov 8 at 16:42












up vote
0
down vote










up vote
0
down vote









You call the static function of WebSettings. It should be: webSettings. setJavaScriptEnabled(true);






share|improve this answer












You call the static function of WebSettings. It should be: webSettings. setJavaScriptEnabled(true);







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 10:27









Louis Solo

1162




1162











  • 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




thank you... it helped me a lot
– user8140535
Nov 8 at 16:42

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto