java - 无法解析构造函数

标签 java android android-studio

我有一个错误,我不知道为什么在我的 Galaxy Ace Samsung (Android 2.3.6) 中不工作,但在我的 Motorola G (Android 4.4) 中工作完美。异常是如此奇怪这是我的代码:

adapter = new SimpleCursorAdapter(this,R.layout.single_row_profession, cursor,from,to,0);

package com.orun.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.orun.database.DataBaseManager;
import com.orun.model.Profession;
import com.orun.s.SConnection;


public class ProfessionsActivity extends Activity {

public static SConnection sConnection;
public static DataBaseManager manager;
private static Cursor cursor;
private static ListView listView;
private static SimpleCursorAdapter adapter;
private static EditText etSearch;
private static ImageButton btSearch;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_professions);
    SharedPreferences sharedPref = getSharedPreferences(getString(R.string.PREFERENCE_FILE_KEY), Context.MODE_PRIVATE);
    Toast.makeText(getApplicationContext(), "Rol "+sharedPref.getString("ROL","Estudiante"),Toast.LENGTH_LONG).show();
    manager = new DataBaseManager(this);
    listView = (ListView) findViewById(R.id.listView);
    etSearch = (EditText)findViewById(R.id.etSearch);
    new LoadTask().execute();
    cursor = manager.searchProfession(etSearch.getText().toString());
    int[] to  = new int[]{R.id.textCode, R.id.textName,R.id.textType};
    String[] from = new String[]{"_id","name","type"};
    try {
        adapter = new SimpleCursorAdapter(this,R.layout.single_row_profession, cursor,from,to,0);
    }catch (Exception e){
        e.printStackTrace();
    }
    listView.setAdapter(adapter);
    etSearch.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            new SearchTask().execute();
            adapter.changeCursor(cursor);

        }
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {}
        public void onTextChanged(CharSequence s, int start, int before,
                                  int count) {}

    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(ProfessionsActivity.this,PrincipalActivity.class);
            int codeProfession = Integer.parseInt(((TextView)(view.findViewById(R.id.textCode))).getText().toString());
            SharedPreferences sharedPref = getSharedPreferences(getString(R.string.PREFERENCE_FILE_KEY), Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putInt("CODE_PROFESSION", codeProfession);
            editor.commit();
            startActivity(intent);
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.professions, 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);
}

private class SearchTask extends AsyncTask<Void, Void, Void>{
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Void doInBackground(Void... params) {
        cursor = manager.searchProfession(etSearch.getText().toString());
        return null;
    }


    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);
    }
}

private class LoadTask extends AsyncTask<Void, Void, Void>{

    @Override
    protected Void doInBackground(Void... params) {
        try {
            sConnection = new SConnection();
            for(Profession p : sConnection.getPlansPreg())
                manager.insertProfession(p.getCode(),p.getName(),"PRE");
            for(Profession p : sConnection.getPlansPos())
                manager.insertProfession(p.getCode(),p.getName(),"POS");

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        Toast.makeText(getApplicationContext(),"Se han cargador todos los planes",Toast.LENGTH_SHORT).show();
    }

}

异常是:无法解析构造函数

'(Landroid/context/Context;ILandroid/database/Cursor;[Ljava/lang/String;[II)V

最佳答案

您正在使用的构造函数是在 API 级别 11 中添加的,因此它在 Android 2.3.6(API 级别 10)中不存在也就不足为奇了。

public SimpleCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to, int flags) Added in API level 11

Standard constructor.

Parameters

context The context where the ListView associated with this SimpleListItemFactory is running

layout resource identifier of a layout file that defines the views for this list item. The layout file should include at least those named views defined in "to"

c The database cursor. Can be null if the cursor is not available yet.

from A list of column names representing the data to bind to the UI. Can be null if the cursor is not available yet.

to The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter. Can be null if the cursor is not available yet.

flags Flags used to determine the behavior of the adapter, as per CursorAdapter(Context, Cursor, int).

参见 class reference .

关于java - 无法解析构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24468874/

相关文章:

java - 如何修复 Selenium ios 驱动程序上的 SessionNotCreatedException?

java - Android 上 Web 上相同图像的不同尺寸

java - 从未使用过的变量

android - 在选项菜单中设置 itemId

android - 不同密度的不同 9-patch 图像?

java - Android Studio 中支持的 @SuppressWarnings 值

带有 Selenium WebDriver 的 Java8

java - R.id 无法解析

java - 如何在 Android Studio 的现有文件中添加作者模板?

android - 请配置Android SDK