gpt4 book ai didi

Android:也许 FEATURE_PROGRESS 导致应用程序不幸停止

转载 作者:行者123 更新时间:2023-11-30 01:57:15 31 4
gpt4 key购买 nike

下面的代码有问题

package com.example.ch13_searchflickrr;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

public class MainActivity extends ActionBarActivity {

WebView wv;
String query = "";
String baseURL = "http://m.flickr.com/#/search/advanced/_QM_q_IS_";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);

wv = (WebView) findViewById(R.id.wv);
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress){
setProgress(progress*100);
}
});
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode==KeyEvent.KEYCODE_BACK &&
wv.canGoBack()){
wv.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}

public void search(View v){


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

在执行上面的代码时,它将显示不幸停止

但是如果我删除该行:

this.getWindow().requestFeature(Window.FEATURE_PROGRESS);

然后应用程序可以运行,所以,我认为问题出在这里,但是,我不知道如何正确使用那条线,谁能给点建议?谢谢!

最佳答案

LogCat 显示

requestfeature must be called before adding content

为了解决这个问题,

requestFeature(Window.FEATURE_PROGRESS); 必须在 super.onCreate(savedInstanceState); 之前调用

应该是:

this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

关于Android:也许 FEATURE_PROGRESS 导致应用程序不幸停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32031207/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com