[英]Cannot resolve method put(java.lang.string, java.lang.string)
I am following a solution placed here , and getting a Cannot resolve method put(java.lang.string, java.lang.string) I am attempting to avert to avert losing the data in my webview on orientation change without handling the orientation change manually. 我正在这里放置一个解决方案,并得到一个Cannot resolve方法put(java.lang.string,java.lang.string)我试图避免在方向更改时避免丢失Webview中的数据,而无需手动处理方向更改。
my code is posted below: 我的代码发布在下面:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.webcontent);
myWebView.getSettings().setJavaScriptEnabled(true); // enable javascript
myWebView.loadUrl("file:///android_asset/Welcome.html");
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
@Override
protected void onPause() {
super.onPause();
SharedPreferences prefs = context.getApplicationContext().
getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE);
Editor edit = prefs.edit();
edit.put("lastUrl",myWebView.getUrl());
edit.commit(); // can use edit.apply() but in this case commit is better
}
@Override
protected void onResume() {
super.onResume();
if(myWebView != null) {
SharedPreferences prefs = context.getApplicationContext().
getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE);
String s = prefs.getString("lastUrl","");
if(!s.equals("")) {
myWebView.loadUrl(s);
}
}
}
Editor doesn't contain a method "put". 编辑器不包含方法“ put”。
Because you want to put an url, you can use Editor.putString instead 因为您要放置一个URL,所以可以改用Editor.putString
So there you go 所以你去了
edit.putString("lastUrl",myWebView.getUrl());
There's no put methods for SharedPreferences.Editor. SharedPreferences.Editor没有放置方法。 The correct one should be
正确的应该是
edit.putString("lastUrl",myWebView.getUrl());
You can find out more here SharedPreferences.Editor 您可以在此处找到更多SharedPreferences.Editor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.