मैं पॉप्युलेट करने के लिए एक MatrixCursor
का उपयोग कर समस्या हो रही है के साथ एक ListView में MatrixCursor और SimpleCursorAdapter का उपयोग करते हुए मेरी ListView
:पाठ और छवियों
private void fillData() {
String[] menuCols = new String[] { "icon", "item", "price" };
int[] to = new int[] { R.id.icon, R.id.item, R.id.price };
MatrixCursor menuCursor = new MatrixCursor(menuCols);
startManagingCursor(menuCursor);
menuCursor.addRow(new Object[] { R.drawable.chicken_sandwich, "Chicken Sandwich", "$3.99" });
SimpleCursorAdapter menuItems = new SimpleCursorAdapter(
this, R.layout.menu_row, menuCursor, menuCols, to);
setListAdapter(menuItems);
}
निर्माण SimpleCursorAdapter
एक दुर्घटना का कारण बनता है। यहां तक कि जब मैंने आइकन को हटाने का प्रयास किया तब भी ऐप क्रैश हो गया। है क्रैश के समय की कॉल स्टैक यहाँ: यहाँ मेरी menu_row.xml
है:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:id="@+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
संपादित
Thread [<3> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2481
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2497
ActivityThread.access$2200(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 119
ActivityThread$H.handleMessage(Message) line: 1848
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4338
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 860
ZygoteInit.main(String[]) line: 618
NativeStart.main(String[]) line: not available [native method]
समाधान:
मैं समस्या और समाधान नीचे मेरे जवाब में है।
जब आप दुर्घटनाग्रस्त हो जाते हैं, तो आप कहां गलत हो रहे हैं, यह पता लगाने में सहायता के लिए स्टैक ट्रेस देख सकते हैं - ग्रहण में एडीबी लॉगकैट, डीडीएमएस, या डीडीएमएस परिप्रेक्ष्य का उपयोग करें। यदि इससे आपको समस्या को ठीक करने में पर्याप्त सहायता नहीं मिलती है, तो स्टैक ट्रेस को अपने प्रश्न के संपादन के रूप में पोस्ट करें, क्योंकि इससे हमें कुछ संकेत मिल सकते हैं। – CommonsWare
उत्कृष्ट सवाल ... मेरी इच्छा है कि मुझे यह दो हफ्ते पहले मिले! नमूना कोड के लिए धन्यवाद। बहुत बढ़िया!! – mobibob