Android Baseadapter Java.lang.ArrayIndexOutOfBoundsException!!!!!!!!!

Source: Internet
Author: User

Recently encountered a very wonderful problem the same code in two different phones present different status a Samsung mobile phone running smoothly no problem a domestic Lenovo mobile phone running out of bounds error

Looking for a long time may be wrong place in the adapter inside can go to low is where the cross-border?

I need to show 2 layouts in a ListView that need to return two values in the Getitemviewtype method at first a value of 1 (chat_come) and a 2 (chat_to) OK should have no problem,

Pay special attention to the wonderful rule of this method is that you must return a 0! But it's still a problem. On the Lenovo phone specifically reiterated on the Samsung Phone no problems

Got a look. Data found that the value returned in the Getitemviewtype method must be less than

The value returned by the Getviewtypecount Method!

That is, no matter how many layout definitions you need to load in the ListView, the type can only start with 0! This is exactly the same as the Getitemviewtype method must return a 0 rule combined on only starting from 0 count

The value of type is less than Getviewtypecount returned!

The number of two returned is then changed to 0 (Chat_come)

One change to 1 (chat_to)

The problem is solved.

What I don't understand is why there's no such problem on Samsung's phone? Test Machine Limited did not test the other domestic mobile phones will have the same phenomenon


Public int getitemviewtype (int position) {

TODO auto-generated Method stub

if (list. Get (position). Iscomemsg ()) {

return Common. Chat_come;

}Else

return Common. chat_to;

}

Android Baseadapter Java.lang.ArrayIndexOutOfBoundsException!!!!!!!!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.