0

これをトラブルシューティングする方法がわかりません。助けてください。私が言える唯一のことは、コメントアウトするsetListAdapter(cursorAdapter);と、コードは実行されますが、ListView. 役立つ可能性のあるコードの他の部分があれば教えてください。ご協力ありがとうございました。

08-06 03:21:50.435: E/AndroidRuntime(489): Uncaught handler: thread main exiting due to uncaught exception
08-06 03:21:50.565: E/AndroidRuntime(489): java.lang.ArrayIndexOutOfBoundsException
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:157)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.CursorAdapter.getView(CursorAdapter.java:186)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.AbsListView.obtainView(AbsListView.java:1274)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.ListView.measureHeightOfChildren(ListView.java:1147)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.ListView.onMeasure(ListView.java:1060)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.view.View.measure(View.java:7964)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:350)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.view.View.measure(View.java:7964)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.view.View.measure(View.java:7964)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:464)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.view.View.measure(View.java:7964)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.view.View.measure(View.java:7964)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.view.ViewRoot.performTraversals(ViewRoot.java:763)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.os.Looper.loop(Looper.java:123)
08-06 03:21:50.565: E/AndroidRuntime(489):    at android.app.ActivityThread.main(ActivityThread.java:4363)
08-06 03:21:50.565: E/AndroidRuntime(489):    at java.lang.reflect.Method.invokeNative(Native Method)
08-06 03:21:50.565: E/AndroidRuntime(489):    at java.lang.reflect.Method.invoke(Method.java:521)
08-06 03:21:50.565: E/AndroidRuntime(489):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-06 03:21:50.565: E/AndroidRuntime(489):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-06 03:21:50.565: E/AndroidRuntime(489):    at dalvik.system.NativeStart.main(Native Method)

私の活動:

public class SearchActivity extends ListActivity {
final String APP_TAG = "RouteTracker";

boolean APP_DEBUG = true;
int searchType;

DbAdapter dbAdapter;

Context context = this;

@Override
public void onResume(){
    dbAdapter.open();
    super.onResume();
}

@Override
public void onPause(){
    dbAdapter.close();
    super.onPause();
}
@Override
public void onCreate(Bundle savedInstanceBundle){
    super.onCreate(savedInstanceBundle);

    if (APP_DEBUG) {Log.d(APP_TAG, "Inside onCreate for SearchActivity");}

    dbAdapter = new DbAdapter(this);

    setContentView(R.layout.search_activity);

    Bundle searchActivityBundle = getIntent().getExtras();
    searchType = searchActivityBundle.getInt("SearchType");

    TextView titleLabel = (TextView) findViewById(R.id.search_activity_title_label);
    titleLabel.setText(getString(R.string.search_activity_default_title_label));

    final EditText search_criteria_edittext = (EditText) findViewById(R.id.search_activity_search_criteria_edittext);

    Button search_button = (Button) findViewById(R.id.search_activity_search_button);
    search_button.setText(getString(R.string.search_activity_search_button));

    //ListView searchResultsList; // = (ListView) findViewById(android.R.id.list);
    //searchResultsList = getListView();

    switch (searchType) {
    case RouteTrackerGlobal.SEARCH_NAME:
        search_criteria_edittext.setHint(getString(R.string.search_activity_textview_company_name_hint));
        break;
    case RouteTrackerGlobal.SEARCH_STREET:
        search_criteria_edittext.setHint(getString(R.string.search_activity_textview_street_hint));
        break;
    case RouteTrackerGlobal.SEARCH_CITY:
        search_criteria_edittext.setHint(getString(R.string.search_activity_textview_city_hint));
        break;
    case RouteTrackerGlobal.SEARCH_STATE:
        search_criteria_edittext.setHint(getString(R.string.search_activity_textview_state_hint));
        break;
    case RouteTrackerGlobal.SEARCH_ZIP:
        search_criteria_edittext.setHint(getString(R.string.search_activity_textview_zip_hint));
        break;
    }

    search_button.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {
            // TODO Auto-generated method stub
            String searchCriteria = search_criteria_edittext.getText().toString();
            if (searchCriteria.trim().equals("")) {
                Toast.makeText(getBaseContext(), "No data entered, try again",Toast.LENGTH_SHORT).show();
                return;
            }

            String[] columns = new String[] {};
            int[] to = new int[] {R.id.search_activity_details_search_results, R.id.search_activity_details_company_name};

            Cursor dataCursor;

            switch (searchType) {
            case RouteTrackerGlobal.SEARCH_NAME:
                dataCursor = dbAdapter.search(searchType, searchCriteria); 
                columns= new String[] {"CompanyName"};
                break;
            case RouteTrackerGlobal.SEARCH_STREET:
                dataCursor = dbAdapter.search(searchType, searchCriteria);
                columns = new String[] {"AddressStreet","CompanyName"};
                break;
            case RouteTrackerGlobal.SEARCH_CITY:
                dataCursor = dbAdapter.search(searchType, searchCriteria);
                columns = new String[] {"AddressCity", "CompanyName"};
                break;
            case RouteTrackerGlobal.SEARCH_STATE:
                dataCursor = dbAdapter.search(searchType, searchCriteria);
                columns = new String[] {"AddressState", "CompanyName"};
                break;
            case RouteTrackerGlobal.SEARCH_ZIP:
                dataCursor = dbAdapter.search(searchType, searchCriteria);
                columns = new String[] {"AddressZip", "CompanyName"};
                break;
            default:
                dataCursor = dbAdapter.search(RouteTrackerGlobal.SEARCH_NAME, searchCriteria);
                columns = new String[] {"", "CompanyName"};
                break;
            }
            startManagingCursor(dataCursor);

            if (dataCursor == null) {
                Toast.makeText(getBaseContext(), "Something happened that failed", Toast.LENGTH_SHORT).show();
                setListAdapter(null);
                return;
            }
            if (dataCursor.getCount() == 0) {
                Toast.makeText(getBaseContext(), getString(R.string.search_activity_no_results), Toast.LENGTH_SHORT).show();
                setListAdapter(null);
                return;
            }
            SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(context, R.layout.search_activity_details, dataCursor, columns, to);
            setListAdapter(cursorAdapter);

            //Toast.makeText(getBaseContext(), dataCursor.getColumnName(1), Toast.LENGTH_SHORT).show();
        }});

Android 2.1 ソースをロードし、どこで失敗したかを見つけることができましたが、まだ理解できません。

bindView 内の SimpleCursorAdapter クラスで失敗します。以下は bindView で、 String text = cursor.getString(from[i]);で失敗します。

public void bindView(View view, Context context, Cursor cursor) {
    final View[] holder = mHolders.get(view);
    final ViewBinder binder = mViewBinder;
    final int count = mTo.length;
    final int[] from = mFrom;

    for (int i = 0; i < count; i++) {
        final View v = holder[i];
        if (v != null) {
            boolean bound = false;
            if (binder != null) {
                bound = binder.setViewValue(v, cursor, from[i]);
            }

            if (!bound) {
                **String text = cursor.getString(from[i]);**
                if (text == null) {
                    text = "";
                }

                if (v instanceof TextView) {
                    setViewText((TextView) v, text);
                } else if (v instanceof ImageView) {
                    setViewImage((ImageView) v, text);
                } else {
                    throw new IllegalStateException(v.getClass().getName() + " is not a " +
                            " view that can be bounds by this SimpleCursorAdapter");
                }
            }
        }
    }
}
4

1 に答える 1

0

変数 i を使用して mTo 配列の長さを数えているようです。mTo のサイズが from[] または holder[] のサイズよりも大きくないことは確かですか? i でこれらの配列のすべてにアクセスしたい場合は、それらがすべて同じ数の要素を持っていることを確認する方がよいためです。そうしないと、問題が発生するだけです。

于 2012-08-06T16:33:16.853 に答える