我从StackOverflow老问答中得到了这个答案。但是当我把它放在Android Studio上时,它会出现错误。怎么解决?请看一下这个截图和这段代码:
public class MainActivity extends AppCompatActivity {
public WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView= (WebView) findViewById(R.id.webView);
WebSettings webSettings= webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("https://obs6.com/");
webView.setWebViewClient(new WebViewClient());
Toast.makeText(LogThirdPager.this, "Hello", Toast.LENGTH_SHORT).show();
reload();
}
public void reload() {
final Handler handler = new Handler() {
@Override
public void publish(LogRecord record) {
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
};
webView.postDelayed(new Runnable() {
Toast.makeText(LogThirdPager.this, "Hello", Toast.LENGTH_SHORT).show();
reload();
},5000);
}
}
答案 0 :(得分:0)
将LogThirdPager.this
两行更改为MainActivity.this
。无法从LogThirdPager.this
引用MainActivity
。