بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
مشکل nullpointerexceptionدر کد آداپتر (حل شده)
به نظر شما چرا از خط مشخص شده شده ارور null میگیره؟
public class MyAdapter extends ArrayAdapter<Item> implements PinnedSectionListAdapter {
private static final int[] COLORS = new int[]{ R.color.blue_light };
private static final String[] sectionTitle = new String[]{ "title1", "title2", "title3", "title4", "title5" };
public MyAdapter(ArrayList<Item> array) {
super(G.context, R.layout.list_row, array);
//===============section==============================================
final int sectionsNumber = 5;
prepareSections(sectionsNumber);
int sectionPosition = 0, listPosition = 0;
for (char i = 0; i < sectionsNumber; i++) {
Item section = new Item(Item.SECTION, sectionTitle[i], (float) (Math.random() * 5));
section.sectionPosition = sectionPosition;
section.listPosition = listPosition++;
onSectionAdded(section, sectionPosition);
add(section);
//===============item==============================================
final int itemsNumber = 10; //(int) Math.abs((Math.cos(2f * Math.PI / 3f * sectionsNumber / (i + 1f)) * 25f));
for (int j = 0; j < itemsNumber; j++) {
Item item = new Item(Item.ITEM, "game" + j, (float) (Math.random() * 5));
item.sectionPosition = sectionPosition;
item.listPosition = listPosition++;
add(item);
}
sectionPosition++;
}
}
protected void prepareSections(int sectionsNumber) {}
protected void onSectionAdded(Item section, int sectionPosition) {}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TextView view = (TextView) super.getView(position, convertView, parent);
// view.setTextColor(Color.DKGRAY);
View view = convertView;
Item item = getItem(position);
if (view == null)
{
if (item.type == Item.SECTION)
{
view = G.inflater.inflate(R.layout.section_list_item, null);
} else
{
view = G.inflater.inflate(R.layout.list_row, null);
}
}
if (position % 2 == 0) {
view.setBackgroundResource(R.drawable.list_background_alternate);
} else {
view.setBackgroundResource(R.drawable.list_backgroundcolor);
}
view.setTag("" + position);
if (item.type == Item.SECTION)
{
//view.setOnClickListener(PinnedSectionListActivity.this);
view.setBackgroundColor(parent.getResources().getColor(COLORS[item.sectionPosition % COLORS.length]));
}
TextView text = (TextView) view.findViewById(R.id.txtname);
RatingBar rate = (RatingBar) view.findViewById(R.id.rating);
if (text != null) {
text.setText(item.text);
rate.setRating(2.5f); این خط ارور داره
}
return view;
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public int getItemViewType(int position) {
return getItem(position).type;
}
@Override
public boolean isItemViewTypePinned(int viewType) {
return viewType == Item.SECTION;
}
}
0
0
الان فقط text رو چک کردی که null نباشه rate رو هم چک کن - بعدش هم بجای 2.5 عدد صحیح مثل 2 بزار ببین فرق میکنه (11 سال پیش)
0
0
بیرون از اون شرط هم میذارم باز ارور میده اصلا انگار پر نمیشه نمیدونم چرا (11 سال پیش)
0
0
بیرون شرط نزار ;i ، داخل شرط بزار ببین rate هم null نباشه (11 سال پیش)
0
0
اااا درست شد !!!! مرسی واقعا ولی چه ربطی داشت آخه (11 سال پیش)
برای این سوال پاسخی وجود ندارد.
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .