我的情景是,我有一些數據在數據庫SQLite
。我能得到數據的正確的,拋出OutOfMemoryError Android
Cursor c0 = OCTDBHelper.myDataBase.rawQuery("SELECT DISTINCT ALIAS FROM ICT32 where ALIAS NOT NULL", null);
Log.i("IC-Count", "IC-Count : " + c0.getCount());
String arr[] =new String[c0.getCount()];
c0.moveToFirst();
for(int i = 0; i < c0.getCount(); i++)
{
arr[i] = c0.getString(0);
c0.moveToNext();
}
在這裏,我得到了所有數據的正確arr
一樣,
ARR [0]:ABCB,hjhj,jkshdf,hdjf,GHSG,aghgh,
arr [1]:klkl,sdjk,jkji,iui,jiji,jij,
。 。 。
ARR [N]:QW,rwer,重,TR,YTY,烏尤,RTR,叔,ETR,YRT,YTR
ie
,每個位置具有10-30的數據與comma(,)
。 total arr.length is 1322
獲取數據後,我需要做一些操作與數據遵循,
我需要根據
comma(,)
split(",")
並加入到單List
直到陣列達到n'th
位置。最後我的輸出應該是,
列表[0]:ABCB
列表[1]:hjhj
名單[2]:jkshdf
...
list [n-1]:yrt
列表[N]:YTR
我認爲已經正確做到了。但它給像Throwing OutOfMemoryError
我的代碼錯誤,
Cursor c0 = OCTDBHelper.myDataBase.rawQuery("SELECT DISTINCT ALIAS FROM ICT32 where ALIAS NOT NULL", null);
Log.i("IC-Count", "IC-Count : " + c0.getCount());
ArrayList<String> tmp = new ArrayList<>();
c0.moveToFirst();
for(int i = 0; i < c0.getCount(); i++)
{
String arr[] = c0.getString(0).split(",");
for(int j= 0; j< arr.length;i++)
{
if(!arr[j].equals(","))
{
tmp.add(arr[j]);
}
}
c0.moveToNext();
}
Log.i("Alias" , "count : " +tmp.size());
這個代碼給出Throwing OutOfMemoryError
logcat的
FATAL EXCEPTION: main
Process: estec.android.mvi32, PID: 11005
java.lang.OutOfMemoryError: Failed to allocate a 103059952 byte allocation with 16777120 free bytes and 58MB until OOM
at java.util.ArrayList.add(ArrayList.java:118)
at estec.android.mvi32.OCTActivity.onOptionsItemSelected(OCTActivity.java:294)
at android.app.Activity.onMenuItemSelected(Activity.java:2882)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:353)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:144)
at android.support.v7.internal.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:99)
at android.support.v7.app.AppCompatDelegateImplV7.onMenuItemSelected(AppCompatDelegateImplV7.java:541)
at android.support.v7.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
at android.support.v7.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:153)
at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:948)
at android.support.v7.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:187)
at android.widget.AdapterView.performItemClick(AdapterView.java:300)
at android.widget.AbsListView.performItemClick(AbsListView.java:1143)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3044)
at android.widget.AbsListView.onTouchUp(AbsListView.java:3872)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3627)
at android.view.View.dispatchTouchEvent(View.java:8388)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2424)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2158)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at android.widget.PopupWindow$PopupViewContainer.dispatchTouchEvent(PopupWindow.java:1682)
at android.view.View.dispatchPointerEvent(View.java:8578)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4021)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3887)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3468)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3578)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3476)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3635)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3468)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3476)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5701)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5675)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5646)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5791)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:143)
at android.os.Looper.loop(Looper.java:122)
at android.app.ActivityThread.main(ActivityThread.java:5253)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
如何解決這個問題?。
請評論downvote的原因? –
您的數組列表添加了無限項目,並使用此行對for(int j = 0; j
@SathishKumarJ學習進行調試,您將節省大量時間。還要注意複製粘貼代碼是導致此類錯誤的不良做法。 – m0skit0