无效的列表操作:索引0,大小0。

huangapple go评论100阅读模式
英文:

Invalid list operation: index 0, size 0

问题

这是我在编辑文本更改时的代码(问题出现在我想要为listview(publicapps)进行搜索时)

我该怎么做来修复这个错误... 问题出现在我键入与 _charSeq 不相等的内容时

据我了解,在地图(pubmap)删除位置时会产生错误

  1. if (stris.equals("p")) {
  2. if (Searchby.equals("1")) {
  3. progressbar6.setVisibility(View.VISIBLE);
  4. pub.addListenerForSingleValueEvent(new ValueEventListener() {
  5. @Override
  6. public void onDataChange(DataSnapshot _dataSnapshot) {
  7. pubmap = new ArrayList<>();
  8. try {
  9. GenericTypeIndicator<HashMap<String, Object>> _ind = new GenericTypeIndicator<HashMap<String, Object>>() {};
  10. for (DataSnapshot _data : _dataSnapshot.getChildren()) {
  11. HashMap<String, Object> _map = _data.getValue(_ind);
  12. pubmap.add(_map);
  13. }
  14. }
  15. catch (Exception _e) {
  16. _e.printStackTrace();
  17. }
  18. if (_charSeq.length() > 0) {
  19. n3 = pubmap.size() - 1;
  20. n4 = pubmap.size();
  21. for(int _repeat84 = 0; _repeat84 < (int)(n4); _repeat84++) {
  22. if (pubmap.get((int)n3).get("pubflair").toString().toLowerCase().contains(_charSeq.toLowerCase())) {
  23. }
  24. else {
  25. pubmap.remove((int)(n3));
  26. }
  27. n3--;
  28. }
  29. }
  30. publicapps.setAdapter(new PublicappsAdapter(pubmap));
  31. progressbar6.setVisibility(View.GONE);
  32. }
  33. @Override
  34. public void onCancelled(DatabaseError _databaseError) {
  35. }
  36. });
  37. }
  38. else {
  39. progressbar6.setVisibility(View.VISIBLE);
  40. pub.addListenerForSingleValueEvent(new ValueEventListener() {
  41. @Override
  42. public void onDataChange(DataSnapshot _dataSnapshot) {
  43. pubmap = new ArrayList<>();
  44. try {
  45. GenericTypeIndicator<HashMap<String, Object>> _ind = new GenericTypeIndicator<HashMap<String, Object>>() {};
  46. for (DataSnapshot _data : _dataSnapshot.getChildren()) {
  47. HashMap<String, Object> _map = _data.getValue(_ind);
  48. pubmap.add(_map);
  49. }
  50. }
  51. catch (Exception _e) {
  52. _e.printStackTrace();
  53. }
  54. if (_charSeq.length() > 0) {
  55. n3 = pubmap.size() - 1;
  56. n4 = pubmap.size();
  57. for(int _repeat146 = 0; _repeat146 < (int)(n4); _repeat146++) {
  58. if (pubmap.get((int)n3).get("pubname").toString().toLowerCase().contains(_charSeq.toLowerCase())) {
  59. }
  60. else {
  61. pubmap.remove((int)(n3));
  62. }
  63. n3--;
  64. }
  65. }
  66. publicapps.setAdapter(new PublicappsAdapter(pubmap));
  67. progressbar6.setVisibility(View.GONE);
  68. }
  69. @Override
  70. public void onCancelled(DatabaseError _databaseError) {
  71. }
  72. });
  73. }
  74. }
英文:

Here's my code when edit text changed (the problem appeared after i wanted to make a search for listview(publicapps) using edittext)

What should i do to fix the error... The problem appears when i type something that is not equals the _charSeq

As i got it gives an error when the map (pubmap) deletes the position

  1. if (stris.equals(&quot;p&quot;)) {
  2. if (Searchby.equals(&quot;1&quot;)) {
  3. progressbar6.setVisibility(View.VISIBLE);
  4. pub.addListenerForSingleValueEvent(new ValueEventListener() {
  5. @Override
  6. public void onDataChange(DataSnapshot _dataSnapshot) {
  7. pubmap = new ArrayList&lt;&gt;();
  8. try {
  9. GenericTypeIndicator&lt;HashMap&lt;String, Object&gt;&gt; _ind = new GenericTypeIndicator&lt;HashMap&lt;String, Object&gt;&gt;() {};
  10. for (DataSnapshot _data : _dataSnapshot.getChildren()) {
  11. HashMap&lt;String, Object&gt; _map = _data.getValue(_ind);
  12. pubmap.add(_map);
  13. }
  14. }
  15. catch (Exception _e) {
  16. _e.printStackTrace();
  17. }
  18. if (_charSeq.length() &gt; 0) {
  19. n3 = pubmap.size() - 1;
  20. n4 = pubmap.size();
  21. for(int _repeat84 = 0; _repeat84 &lt; (int)(n4); _repeat84++) {
  22. if (pubmap.get((int)n3).get(&quot;pubflair&quot;).toString().toLowerCase().contains(_charSeq.toLowerCase())) {
  23. }
  24. else {
  25. pubmap.remove((int)(n3));
  26. }
  27. n3--;
  28. }
  29. }
  30. publicapps.setAdapter(new PublicappsAdapter(pubmap));
  31. progressbar6.setVisibility(View.GONE);
  32. }
  33. @Override
  34. public void onCancelled(DatabaseError _databaseError) {
  35. }
  36. });
  37. }
  38. else {
  39. progressbar6.setVisibility(View.VISIBLE);
  40. pub.addListenerForSingleValueEvent(new ValueEventListener() {
  41. @Override
  42. public void onDataChange(DataSnapshot _dataSnapshot) {
  43. pubmap = new ArrayList&lt;&gt;();
  44. try {
  45. GenericTypeIndicator&lt;HashMap&lt;String, Object&gt;&gt; _ind = new GenericTypeIndicator&lt;HashMap&lt;String, Object&gt;&gt;() {};
  46. for (DataSnapshot _data : _dataSnapshot.getChildren()) {
  47. HashMap&lt;String, Object&gt; _map = _data.getValue(_ind);
  48. pubmap.add(_map);
  49. }
  50. }
  51. catch (Exception _e) {
  52. _e.printStackTrace();
  53. }
  54. if (_charSeq.length() &gt; 0) {
  55. n3 = pubmap.size() - 1;
  56. n4 = pubmap.size();
  57. for(int _repeat146 = 0; _repeat146 &lt; (int)(n4); _repeat146++) {
  58. if (pubmap.get((int)n3).get(&quot;pubname&quot;).toString().toLowerCase().contains(_charSeq.toLowerCase())) {
  59. }
  60. else {
  61. pubmap.remove((int)(n3));
  62. }
  63. n3--;
  64. }
  65. }
  66. publicapps.setAdapter(new PublicappsAdapter(pubmap));
  67. progressbar6.setVisibility(View.GONE);
  68. }
  69. @Override
  70. public void onCancelled(DatabaseError _databaseError) {
  71. }
  72. });
  73. }
  74. } ```
  75. </details>
  76. # 答案1
  77. **得分**: 0
  78. 首先,我建议您将您的代码划分为小的功能部分,因为当您遇到问题时,更容易找到错误。
  79. 显然,*bupmap* 是空的或者索引不存在(通过参数 "int"(n3)传递)。请问您能将堆栈错误信息在这里写出吗?
  80. 祝好!
  81. <details>
  82. <summary>英文:</summary>
  83. first I recommended to you divide your code into small functionality cause when u have a problem is easier found an error.
  84. apparently *bupmap* is empty or not exist an index ( pass by params &quot; int)(n3) &quot;)..please can u write the stack error here?
  85. regards!!
  86. </details>

huangapple
  • 本文由 发表于 2020年9月19日 01:02:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/63959966.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定