In my application I write some codes and this codes I used string.
I want use UTF-8 languages (Farsi), But after run application show me error and force close application.
But when use English language not show me any error and run successfully!!
My codes :
this.q.put("dry land swim", Integer.valueOf(R.array.dry_land_swim));
TypedArray obtainTypedArray = getResources().obtainTypedArray(((Integer) this.q.get(stringArray[i])).intValue());
int length = obtainTypedArray.length();
int[] iArr2 = new int[length];
WorkoutData workoutData = new WorkoutData();
for (int i2 = 0; i2 < length; i2++) {
iArr2[i2] = obtainTypedArray.getResourceId(i2, -1);
}
workoutData.setExcName(stringArray[i]);
Log.e("ShowError", "" + (this.r.get(stringArray[i])).intValue());
workoutData.setExcDescResId(((Integer) this.r.get(stringArray[i])).intValue());
When change this line text (from En to Fa) :
this.q.put("تست", Integer.valueOf(R.array.dry_land_swim));
Show me error for this lines :
TypedArray obtainTypedArray = getResources().obtainTypedArray(((Integer) this.q.get(stringArray[i])).intValue());
workoutData.setExcDescResId(((Integer) this.r.get(stringArray[i])).intValue());
Error message :
java.lang.RuntimeException: Unable to start receiver com.crazytrends.healthmanager.WalkandStep.receivers.HardwareStepCountReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.crazytrends.healthmanager/.WalkandStep.services.HardwareStepCounterService }: app is in background uid UidRecord{528e8bd u0a841 RCVR idle change:idle|uncached procs:1 seq(0,0,0)}
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4452)
at android.app.ActivityThread.access$1600(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2159)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8512)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.crazytrends.healthmanager/.WalkandStep.services.HardwareStepCounterService }: app is in background uid UidRecord{528e8bd u0a841 RCVR idle change:idle|uncached procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1795)
at android.app.ContextImpl.startService(ContextImpl.java:1740)
at android.content.ContextWrapper.startService(ContextWrapper.java:738)
at android.content.ContextWrapper.startService(ContextWrapper.java:738)
at com.crazytrends.healthmanager.WalkandStep.receivers.HardwareStepCountReceiver.onReceive(HardwareStepCountReceiver.java:22)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4443)
How can I Fix it?
Related
I am using redmadrobot:inputmask to use card number input mask. Input mask is working properly, but when I try to delete digits from my input, the application crashes.
Here is my code.
ArrayList<String> affineFormats = new ArrayList<>();
affineFormats.add("[0000] [000] [000] [000]");
affineFormats.add("[0000] [000000] [00000]");
affineFormats.add("[0000] [0000] [0000] [0000]");
String format = "[0000] [000] [000] [000]";
MaskedTextChangedListener listener = new MaskedTextChangedListener(
format,
affineFormats,
AffinityCalculationStrategy.CAPACITY,
true,
etCardNumber,
null,
new MaskedTextChangedListener.ValueListener() {
#Override
public void onTextChanged(boolean b, String s, String s1) {
//here some code
}
});
etCardNumber.addTextChangedListener(listener);
Error Log:
java.lang.IndexOutOfBoundsException: setSpan (21 ... 21) ends beyond length 20
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1108)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:680)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:673)
at android.text.Selection.setSelection(Selection.java:76)
at android.text.Selection.setSelection(Selection.java:87)
at android.widget.EditText.setSelection(EditText.java:104)
at com.redmadrobot.inputmask.MaskedTextChangedListener.afterTextChanged(MaskedTextChangedListener.kt:192)
at android.widget.TextView.sendAfterTextChanged(TextView.java:8366)
at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:10557)
at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1061)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:573)
at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:233)
at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:229)
at android.view.inputmethod.BaseInputConnection.deleteSurroundingText(BaseInputConnection.java:252)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:389)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5763)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
Please help me resolve this issue.
Make sure you defined
<EditText
...
android:digits="0123456789 "
...
/>
for you input field, including space, as allowed symbol, because it is allowed in your mask.
You can do the same programmatically
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
editText.setKeyListener(DigitsKeyListener.getInstance("0123456789 "));
Worked for me.
ContentResolver musicResolver = getContentResolver();
Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri,null,null,null,null);
if(musicCursor!=null && musicCursor.moveToFirst()){
int idColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media._ID);
int titleColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
int artistColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int imageColumn = musicCursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART);
//Add songs to the array list
do{
String theArt = musicCursor.getString(imageColumn);
Bitmap image = BitmapFactory.decodeFile(theArt);
long songId = musicCursor.getLong(idColumn);
String songTitle = musicCursor.getString(titleColumn);
String songArtist = musicCursor.getString(artistColumn);
songsArrayList.add(new Songs(songId,songTitle,songArtist,image));
}while (musicCursor.moveToNext())
I want to get the cover image of the song which i am getting from the local storage, I have no idea how to do it so i get
int imageColumn =
musicCursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART);
this code on internet to get album art this is showing error when i get string from it . That accessing column -1 , I think its not getting the right column to get the image , please let me know how to get the image from media in the way of above code
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.downloadbro.mumusic, PID: 10877
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.downloadbro.mumusic/com.downloadbro.mumusic.MainActivity}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2755)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2816)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1555)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6383)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
at android.database.CursorWrapper.getString(CursorWrapper.java:137)
at com.downloadbro.mumusic.MainActivity.getSongList(MainActivity.java:80)
at com.downloadbro.mumusic.MainActivity.onCreate(MainActivity.java:45)
at android.app.Activity.performCreate(Activity.java:6861)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
And this may give me album art but i want media art no function as such showing to me
Sometimes on my android live wallpaper I get this exception on RESIZE: IllegalArgumentException: Bad position 8/0
latest libgdx
java.lang.IllegalArgumentException: Bad position 8/0
at java.nio.Buffer.position(Buffer.java:249)
at com.badlogic.gdx.graphics.glutils.VertexArray.bind(VertexArray.java:118)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:391)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:382)
at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:490)
at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:460)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.flush(SpriteBatch.java:977)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.setProjectionMatrix(SpriteBatch.java:1049)
at hu.lacas.newalienlwp.Renderer.resizeBatch(Renderer.kt:844)
at hu.lacas.newalienlwp.Renderer.access$resizeBatch(Renderer.kt:44)
at hu.lacas.newalienlwp.Renderer$resize$1.run(Renderer.kt:828)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
The source code
#override fun resize(width: Int, height: Int) {
camera.viewportHeight = Gdx.graphics.height.toFloat()
camera.viewportWidth = Gdx.graphics.width.toFloat()
mOrientation = if (camera.viewportHeight < camera.viewportWidth) LiveWallpaper.ORIENTATION_LANDSCAPE else LiveWallpaper.ORIENTATION_PORTRAIT
camera.fieldOfView = (if (mOrientation != LiveWallpaper.ORIENTATION_LANDSCAPE) 27 else 20).toFloat()
camera.update()
handler.postDelayed({
resizeBatch()
}, 900)
}
private fun resizeBatch() {
val viewportWidth = Gdx.graphics.width
val viewportHeight = Gdx.graphics.height
if (camera2D == null) camera2D = OrthographicCamera()
camera2D?.setToOrtho(false, viewportWidth.toFloat(), viewportHeight.toFloat())
camera2D?.update()
spriteBatch!!.projectionMatrix = camera2D?.combined
Objects.textureRegionScanlineFullScreen.setRegion(0, 0, Gdx.graphics.width, Gdx.graphics.height)
}
it looks like the problem is here:
--> spriteBatch!!.projectionMatrix = camera2D?.combined
This exception is just comes up sometimes... So not really understand what is going on. I created that handler with 900ms because when this is not there the exception is shown more.. Whats is going on?
Libgdx not loaded the matrix yet?
Yesterday from Crashlytics I noticed disk I/O error (code 522) while opening the database. Problem is that this crashed already has been reported from 16 users 36 times. Sadly I can't reproduce this error. Here's the code fragment where error occurs
SessionDbManager(Context context, String tripDbFileName) {
this.context = context;
this.tripDbFileName = tripDbFileName;
this.tripDbHelper = new SessionDbHelper(this.context, tripDbFileName);
SQLiteDatabase database = null;
int attempt = 1;
while (database == null) {
try {
database = this.tripDbHelper.getWritableDatabase(); // here's the error
} catch (android.database.sqlite.SQLiteException e) {
Crashlytics.logException(e);
XLog.e("Failed to load history data from database ", e);
if (attempt == 5) throw e;
}
attempt++;
}
db = database;
}
And here's the stack trace
Fatal Exception: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 522): , while compiling: PRAGMA journal_mode
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:932)
at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:677)
at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:363)
at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:337)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:251)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:195)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:737)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:289)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at eu.fishingapp.data.sql.session.SessionDbManager.(SourceFile:51)
at eu.fishingapp.data.sql.session.SessionContentProvider.update(SourceFile:753)
at android.content.ContentProvider$Transport.update(ContentProvider.java:384)
at android.content.ContentResolver.update(ContentResolver.java:1412)
at eu.fishingapp.data.sql.session.SessionDbHelper.renameSessionDb(SourceFile:584)
at eu.fishingapp.data.network.synchronization.FileSyncServiceImpl.uploadFile(SourceFile:462)
at eu.fishingapp.data.network.synchronization.FileSyncServiceImpl.uploadSessions(SourceFile:221)
at eu.fishingapp.data.network.synchronization.FileSyncServiceImpl.uploadSessionsFiles(SourceFile:243)
at eu.fishingapp.data.network.synchronization.FileSyncIntentService.onHandleIntent(SourceFile:116)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:67)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
I have read about I/O error and found two possible answers I was thinking that this is because users ran out of free space on their devices. But here's some images from two app users
So this is definitely not storage issue :( Any ideas how to solve this problem?
EDIT: targetSdk version 22
My Scenario is, I have some data's in Database SQLite. I can get data's Correctly by,
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();
}
here i got all data's correctly in arr like,
arr[0] :abcb,hjhj,jkshdf,hdjf,ghsg,aghgh,
arr[1] : klkl,sdjk,jkji,iui,jiji,jij,
.
.
.
arr[n] : qw,rwer,re,tr,yty,uyu,rtr,ter,etr,yrt,ytr
ie, each location has 10-30 data with comma(,). total arr.length is 1322
after getting that data i need to do some operation with those data as follow as,
I need to split(",") based on comma(,) and add into Single List until array reach n'th position.
Finally my output should be,
list[0] : abcb
list[1] : hjhj
list[2] : jkshdf
...
list[n-1] : yrt
list[n] : ytr
I think already did correctly. but it gives error like Throwing OutOfMemoryError
My code is,
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());
this code gives 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)
How to resolve this problem??.
This for loop never terminates, look close at the last part:
for(int j= 0; j< arr.length;i++)
Change the i++ to j++ to fix this bug.