我无法理解的Android错误。有人能帮我吗?

时间:2013-08-19 13:29:36

标签: android sdk runtime-error searchview

我已经构建了一个sql数据库,我已经实现了searchview小部件,可以在android pre API 11中使用

当我尝试进行研究时,应用程序关闭自己,我收到此错误和其他消息:

错误

  08-19 15:15:25.560: E/dalvikvm(6838): Could not find class 'android.support.v7.widget.SearchView$5', referenced from method android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11        
 08-19 15:15:25.560: I/dalvikvm(6838): Failed resolving Landroid/support/v7/widget/SearchView$5; interface 814 'Landroid/view/View$OnLayoutChangeListener;'             
 08-19 15:15:25.560: W/dalvikvm(6838): Link of class 'Landroid/support/v7/widget/SearchView$5;' failed    
 08-19 15:15:25.560: D/dalvikvm(6838): VFY: replacing opcode 0x22 at 0x0002   
 08-19 15:15:25.560: D/dalvikvm(6838): VFY: dead code 0x0004-000a in Landroid/support/v7/widget/SearchView;.addOnLayoutChangeListenerToDropDownAnchorSDK11 ()V

我不知道我的代码是否有问题。 有人可以帮助我吗? 谢谢

我认为错误就在这里

import android.app.ListActivity;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ListView;



public class SearchableActivity extends ListActivity{
DatabaseTable db = new DatabaseTable(this);
final Context context=this;
ListView list;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);
        list=(ListView)findViewById(android.R.id.list);
        handleIntent(getIntent());

    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handleIntent(getIntent());
    }


    private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        Cursor c = db.getWordMatches(query, null);
        c.moveToFirst();    
        }
    }
}

我曾尝试导入android.support.v7.widget.Searchview,但它表示从未使用过,并且错误不会消失。对于这个项目,我创建了MainActivity.Java,它包含SearchWidget,DatabaseTable.java和一个包含数据的definitions.txt,一个Search.xml和一个SearchActivity.Java(下面的代码),我也放了MainActivity和SearchActivity中的元标记,在Manifest内部,不知道是否可以在这里插入每个页面的代码...我真的不知道该怎么办!!

当然,这是我主要活动的代码

    import android.os.Bundle;
    import android.app.SearchManager;
    import android.content.Context;
    import android.content.Intent;
    import android.support.v7.widget.SearchView;
    import android.support.v4.view.MenuItemCompat;
    import android.support.v7.app.ActionBar;
    import android.support.v7.app.ActionBarActivity;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;

    public class MainActivity extends ActionBarActivity implements OnClickListener{




    ActionBar actionBar;
    Button a;
    Button b;
    Button c;
    Button d;
    Button e;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        actionBar = getSupportActionBar();
        actionBar.setTitle("Trial");

        initialiseOnClick();
        a.setOnClickListener(this);
        b.setOnClickListener(this);
        c.setOnClickListener(this);
        d.setOnClickListener(this);
        e.setOnClickListener(this);
    }

        //START SEARCHVIEWWIDGET
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        MenuItem searchItem = menu.findItem(R.id.action_search);

        SearchManager searchManager = (SearchManager)     getSystemService(Context.SEARCH_SERVICE);

        SearchView searchView = (SearchView)     MenuItemCompat.getActionView(searchItem);
    // Configure the search info and add any event listeners
       searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(true); 
        return super.onCreateOptionsMenu(menu);



    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_search:
                onSearchRequested();
                return true;
            default:
                return false;
        }
    }

    // END SEARCHVIEWWIDGET

    private void initialiseOnClick() {
        // TODO Auto-generated method stub
        a = (Button) findViewById (R.id.button_a);
        b = (Button) findViewById (R.id.button_b);
        c = (Button) findViewById (R.id.button_c);
        d = (Button) findViewById (R.id.button_d);
        e = (Button) findViewById (R.id.button_e);
    }



    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){

        case R.id.button_a:
            Intent a = new Intent(MainActivity.this, EuropeActivity.class);
            startActivity(a);
        break;

        case R.id.button_b:
            Intent b = new Intent(MainActivity.this, AmericasActivity.class);
            startActivity(b);
        break;

        case R.id.button_c:
            Intent c = new Intent(MainActivity.this, AsiaActivity.class);
            startActivity(c);
        break;

        case R.id.button_d:
            Intent d = new Intent(MainActivity.this, OceaniaActivity.class);
            startActivity(d);
        break;

        case R.id.button_e:
            Intent e = new Intent(MainActivity.this, AfricaActivity.class);
            startActivity(e);
        break;

        }
    }
}

0 个答案:

没有答案