Android:也许FEATURE_PROGRESS导致app不幸停止了

时间:2015-08-16 02:07:55

标签: android

我的代码存在问题

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

执行上面的代码时, 它会显示unfortunately stopped

但如果删除该行:

  

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

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

1 个答案:

答案 0 :(得分:1)

LogCat显示

  

在添加内容之前必须调用requestfeature

要解决这个问题,

#include <iostream> #include <Windows.h> #include <time.h> const float frame_length = 1; using namespace std; int main () { char test[40]; clock_t t; t = clock(); int counter = 0; while (clock() - t < (3000 * frame_length)){ //cin >> test[counter]; //i have added Sleep(200) here to prevent //picking up a single key stroke as many key strokes. Sleep(200); for(int key = 0x41; key < 0x5a; key++) { if(GetAsyncKeyState(key)) { test[counter] = char(key); cout << char(key) << endl; counter ++ ; break; } } } cout << endl << "STOP" << endl; } 必须在requestFeature(Window.FEATURE_PROGRESS);

之前调用

应该是:

super.onCreate(savedInstanceState);