DecimalFormatSymbols exception - android

UnsupportedOperationException (#DecimalFormatSymbols:getMinusSign:300) {main}
I've translated my app in arabic.
On my devices all is ok, but in Google Analytics I received a lot of this error from arabic users.
On my device all works also when I set my devices into arabic.
Any ideas?
EDIT:
DecimalFormatSymbols nf = new DecimalFormatSymbols();
try
{
nf.setDecimalSeparator(sharedPref.getString("pref_currency_decimal_separator", ".").charAt(0));
nf.setGroupingSeparator(sharedPref.getString("pref_currency_thousands_separator", ",").charAt(0));
formatter_currency.setDecimalFormatSymbols(nf);
final int digits = sharedPref.getInt("pref_currency_decimal_places", 2);
formatter_currency.setMaximumFractionDigits(digits);
formatter_currency.setMinimumFractionDigits(digits);
}
catch(IllegalArgumentException e)
{
currency = "$";
nf.setDecimalSeparator('.');
nf.setGroupingSeparator(',');
formatter_currency.setDecimalFormatSymbols(nf);
formatter_currency.setMaximumFractionDigits(2);
formatter_currency.setMinimumFractionDigits(2);
}
catch(UnsupportedOperationException e)
{ }
Logcat:
java.lang.UnsupportedOperationException: Minus sign spans multiple characters: ‏-
at java.text.DecimalFormatSymbols.getMinusSign(DecimalFormatSymbols.java:300)
at java.text.DecimalFormatSymbols.writeObject(DecimalFormatSymbols.java:611)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1033)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:904)
at java.io.ObjectOutputStream.writeFields(ObjectOutputStream.java:863)
at java.text.DecimalFormat.writeObject(DecimalFormat.java:1129)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1033)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at android.os.Parcel.writeSerializable(Parcel.java:1383)
at android.os.Parcel.writeValue(Parcel.java:1335)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1096)
at android.os.Parcel.writeBundle(Parcel.java:663)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2952)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3568)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
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:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

The problem happen only in rtl locales (arabic, hebrew, etc.) after android API 21.
The problem will be fixed in the next releases.
https://code.google.com/p/android/issues/detail?id=170718

Related

IllegalArgumentException: Invalid primitive conversion from boolean to int

my status
Android 6.0 crash, other android version normal
if i set minifyEnabled = false , no crash
if i set minifyEnabled = true , will crash
when activity is not visibility the error appear
it's like error when saving state
my err is :
java.lang.IllegalArgumentException: Invalid primitive conversion from boolean to int
at java.lang.reflect.Field.getInt(Native Method)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:946)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at android.os.Parcel.writeSerializable(Parcel.java:1442)
at android.os.Parcel.writeValue(Parcel.java:1395)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:665)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
at android.os.Bundle.writeToParcel(Bundle.java:1079)
at android.os.Parcel.writeBundle(Parcel.java:690)
at android.os.Parcel.writeValue(Parcel.java:1319)
at android.os.Parcel.writeSparseArray(Parcel.java:778)
at android.os.Parcel.writeValue(Parcel.java:1347)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:665)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
at android.os.Bundle.writeToParcel(Bundle.java:1079)
at android.os.Parcel.writeBundle(Parcel.java:690)
at androidx.fragment.app.FragmentState.writeToParcel(FragmentState.java:127)
at android.os.Parcel.writeTypedList(Parcel.java:1148)
at androidx.fragment.app.FragmentManagerState.writeToParcel(FragmentManagerState.java:51)
at android.os.Parcel.writeParcelable(Parcel.java:1416)
at android.os.Parcel.writeValue(Parcel.java:1322)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:665)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
at android.os.Bundle.writeToParcel(Bundle.java:1079)
at android.os.Parcel.writeBundle(Parcel.java:690)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3152)
at java.lang.reflect.Method.invoke(Native Method)
at f.r.c.i.a.e.invoke(ActivityManagerHook.java:89)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy7.activityStopped(Unknown Source)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3417)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Cannot connect my android studio application with dropbox, but code executes in Eclipse

I am currently having trouble accessing my dropbox account via android studio. I intend to use dropbox to store photos that the user uploads into my application, then store the dropbox filename inside of the database. I have tested this code on Eclipse, and it works like a charm. But I simply cannot get it to work in android studio. I assume I am missing a step somewhere in android studio... but I cannot find what that step may be. I would appreciate any help.
I have added the following to my build.gradle
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.dropbox.core:dropbox-core-sdk:3.1.1'
I have also added this to my android manifest under the package.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Here is the simple code I am attempting to execute. Note that I have my ACCESS_TOKEN stored as a final string, and it does contain the correct access token (as I mentioned previously, I can run this code (and more) perfectly in eclipse).
public void dropbox(){
DbxRequestConfig config = DbxRequestConfig.newBuilder("myapp").build();
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
FullAccount account = null;
try {
account = client.users().getCurrentAccount(); //This is where my error occurs
} catch (DbxException e) {
e.printStackTrace();
}
Log.d("test",account.getName().getDisplayName());
}
Here is the full error message I get.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sigm.fetchyourpet, PID: 8294
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:402)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:6597) 
at android.view.View.performClickInternal(View.java:6574) 
at android.view.View.access$3100(View.java:778) 
at android.view.View$PerformClick.run(View.java:25885) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1513)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:117)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:105)
at java.net.InetAddress.getAllByName(InetAddress.java:1154)
at com.android.okhttp.Dns$1.lookup(Dns.java:39)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:175)
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:141)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:83)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:174)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:258)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:26)
at com.dropbox.core.http.StandardHttpRequestor.getOutputStream(StandardHttpRequestor.java:132)
at com.dropbox.core.http.StandardHttpRequestor.access$000(StandardHttpRequestor.java:29)
at com.dropbox.core.http.StandardHttpRequestor$Uploader.<init>(StandardHttpRequestor.java:141)
at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:73)
at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:29)
at com.dropbox.core.DbxRequestUtil.startPostRaw(DbxRequestUtil.java:275)
at com.dropbox.core.v2.DbxRawClientV2$1.execute(DbxRawClientV2.java:146)
at com.dropbox.core.v2.DbxRawClientV2.executeRetriable(DbxRawClientV2.java:330)
at com.dropbox.core.v2.DbxRawClientV2.executeRetriableWithRefresh(DbxRawClientV2.java:351)
at com.dropbox.core.v2.DbxRawClientV2.rpcStyle(DbxRawClientV2.java:137)
at com.dropbox.core.v2.users.DbxUserUsersRequests.getCurrentAccount(DbxUserUsersRequests.java:120)
at com.sigm.fetchyourpet.MainActivity.dropbox(MainActivity.java:63)
at com.sigm.fetchyourpet.MainActivity.signUp(MainActivity.java:174)
at java.lang.reflect.Method.invoke(Native Method) 
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397) 
at android.view.View.performClick(View.java:6597) 
at android.view.View.performClickInternal(View.java:6574) 
at android.view.View.access$3100(View.java:778) 
at android.view.View$PerformClick.run(View.java:25885) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
This happens because you are running an HTTP request on the main thread, the easy fix:
Thread thread = new Thread() {
#Override
public void run() {
try {
FullAccount account = client.users().getCurrentAccount();
Log.d("test",account.getName().getDisplayName());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();

Can't Generate Certificate Exception When Generating Key Pair In API 21

I've been trying to solve this exception that only happens in Android Lollipop (API 21). I tried to look for other solutions but the only one related is Generate KeyPair with KeyPairGeneratorSpec on API < 23 and the suggested solution didn't work.
Am I missing anything? Thanks!
Here's my code that's throwing at the last line:
Calendar start = Calendar.getInstance();
Calendar end = Calendar.getInstance();
end.add(Calendar.YEAR, 30);
KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(appContext)
.setAlias(getSecureSettingsKeyAlias())
.setSubject(new X500Principal("CN=" + getSecureSettingsKeyAlias()))
.setSerialNumber(BigInteger.TEN)
.setStartDate(start.getTime())
.setEndDate(end.getTime())
.build();
KeyPairGenerator kpg = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, AndroidKeyStore);
kpg.initialize(spec);
kpg.generateKeyPair();
Here's the exception that's happening:
Caused by: java.lang.IllegalStateException: Can't generate certificate
at android.security.AndroidKeyPairGenerator.generateKeyPair(AndroidKeyPairGenerator.java:136)
at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.getKeystore(FileSettingsStorage.java:302)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.writeSecureSettings(FileSettingsStorage.java:185)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSecureSettings(SettingsImpl.java:473)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSettings(SettingsImpl.java:321)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettingsToStorage(sampleIDService.java:102)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettings(sampleIDService.java:91)
at com.sampleid.sampleid.features.shared.BaseActivity.onStop(BaseActivity.java:182)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1261)
at android.app.Activity.performStop(Activity.java:6089)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3341)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3390)
at android.app.ActivityThread.access$1100(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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)
Caused by: java.lang.UnsupportedOperationException: private exponent cannot be extracted
at com.android.org.conscrypt.OpenSSLRSAPrivateKey.getPrivateExponent(OpenSSLRSAPrivateKey.java:161)
at org.spongycastle.jcajce.provider.asymmetric.rsa.RSAUtil.generatePrivateKeyParameter(RSAUtil.java:63)
at org.spongycastle.jcajce.provider.asymmetric.rsa.DigestSignatureSpi.engineInitSign(DigestSignatureSpi.java:95)
at java.security.Signature$SignatureImpl.engineInitSign(Signature.java:679)
at java.security.Signature.initSign(Signature.java:330)
at com.android.org.bouncycastle.x509.X509Util.calculateSignature(X509Util.java:243)
at com.android.org.bouncycastle.x509.X509V3CertificateGenerator.generate(X509V3CertificateGenerator.java:434)
at com.android.org.bouncycastle.x509.X509V3CertificateGenerator.generate(X509V3CertificateGenerator.java:412)
at android.security.AndroidKeyPairGenerator.generateKeyPair(AndroidKeyPairGenerator.java:133)
at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.getKeystore(FileSettingsStorage.java:302)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.writeSecureSettings(FileSettingsStorage.java:185)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSecureSettings(SettingsImpl.java:473)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSettings(SettingsImpl.java:321)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettingsToStorage(sampleIDService.java:102)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettings(sampleIDService.java:91)
at com.sampleid.sampleid.features.shared.BaseActivity.onStop(BaseActivity.java:182)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1261)
at android.app.Activity.performStop(Activity.java:6089)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3341)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3390)
at android.app.ActivityThread.access$1100(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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)
Was finally able to solve this. The issue is with the following:
KeyPairGenerator kpg = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, AndroidKeyStore);
KeyProperties.KEY_ALGORITHM_RSA is only available starting API 23, so it fails in APIs before that. Replace it with "RSA"
Also, if you're using SpongyCastle, it should be added using the following approach:
static {
// as per https://github.com/rtyley/spongycastle/issues/27
Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
}

Only getting first value from a record from cursor when trying to make a method to get a 2d array of strings to represent it

So I've got a database that's got one table, with two fields and one record. I'm using select to retrieve everything from that table, and passing the resulting cursor through this function to try to turn it into a jagged array of strings that will represent the table.
public String[][] cursorTo2dString (Cursor cursor, String[] fields) {
int columnCount = cursor.getColumnCount();
int count = cursor.getCount();
String[][] string2dArray = new String[columnCount][count];
Log.i("StringLengths", count + " & " + columnCount);
Log.i("CursorConts", DatabaseUtils.dumpCursorToString(cursor));
if (cursor.moveToFirst()) {
for (int j=0; j<count && !cursor.isAfterLast(); j++) {
for (int i=0; i<columnCount; i++) {
Log.i("Cursor", cursor.getString(i));
string2dArray[j][i] = cursor.getString(i);
Log.i("StringPoint", string2dArray[j][i]);
}
cursor.moveToNext();
}
}
For reference, whatever appears as the TagIdNo value is currently just a randomly generated number, I'm not actually going to generate this randomly on implementation, I'm just using this for the purposes of testing.
This consistently crashes with the following appearing in the console:
I/StringLengths: 1 & 2
I/CursorConts: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor#bd9f011
0 {
TagIdNo=998
TagName=No Parental Permission
}
<<<<<
I/Cursor: 998
I/StringPoint: 998
I/Cursor: No Parental Permission
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.programming.workingpomproject, PID: 23796
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5226)
at android.view.View$PerformClick.run(View.java:21266)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5226) 
at android.view.View$PerformClick.run(View.java:21266) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:168) 
at android.app.ActivityThread.main(ActivityThread.java:5845) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.example.programming.workingpomproject.DbHelper.cursorTo2dString(DbHelper.java:132)
at com.example.programming.workingpomproject.DbHelper.select(DbHelper.java:89)
at com.example.programming.workingpomproject.DbHelper.select(DbHelper.java:92)
at com.example.programming.workingpomproject.MainActivity.testDbMethodGet(MainActivity.java:66)
at com.example.programming.workingpomproject.MainActivity.dbStuff(MainActivity.java:61)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
at android.view.View.performClick(View.java:5226) 
at android.view.View$PerformClick.run(View.java:21266) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:168) 
at android.app.ActivityThread.main(ActivityThread.java:5845) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 
I've used lots of different methods of taking the contents of the cursor, and no matter what I can only get the first value (the random number in this case) I put into the database. I was wondering if anyone can see why I'm not getting my second value (currently "no parental permission"), and if they could advise me as to how to retrieve it.
Sorry if I've messed up any coding standards; this is my first Android project and my first time in Java but I've been working on this app for a good few months so I'm hoping I'm getting better.
Any and all advice welcome!
EDIT 1:
If, as suggested by Giovanni, I swap the columns and rows in the instantiation, I get this instead:
String[][] string2dArray = new String[count][columnCount];
This leads to the following in the console, in the place of the other results:
I/CursorConts: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor#45e64e9
0 {
TagIdNo=3259
TagName=No Parental Permission
}
<<<<<
I/Cursor: 3259
I/StringPoint: 3259
I/Cursor: No Parental Permission
I/StringPoint: No Parental Permission
I/MovePos: true & false
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.programming.workingpomproject, PID: 24606
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5226)
at android.view.View$PerformClick.run(View.java:21266)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5226)
at android.view.View$PerformClick.run(View.java:21266)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:460)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
at com.example.programming.workingpomproject.DbHelper.cursorTo2dString(DbHelper.java:155)
at com.example.programming.workingpomproject.DbHelper.select(DbHelper.java:89)
at com.example.programming.workingpomproject.DbHelper.select(DbHelper.java:92)
at com.example.programming.workingpomproject.MainActivity.testDbMethodGet(MainActivity.java:66)
at com.example.programming.workingpomproject.MainActivity.dbStuff(MainActivity.java:61)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5226)
at android.view.View$PerformClick.run(View.java:21266)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
This cursor problem seems to be the root problem, the array index one just being something I messed up in an attempt to avoid the cursor error.
Any further help is greatly appreciated!
You got an ArrayIndexOutOfBoundsException, which means that the array you want to assign in, does not have the correct size you are trying to access. For example, if I create an array like:
String[] array = new String[2];
int i = 3;
String s = array[i];
This will throw an exception, since my array has only place for 2 objects, not 3.
Your array is String[][] string2dArray = new String[columnCount][count];
I think you can fix it by changing it to:
String[][] string2dArray = new String[count][columnCount];
Because here:
for (int j = 0; j < count && !cursor.isAfterLast(); j++) {
for (int i = 0; i < columnCount; i++) {
Log.i("Cursor", cursor.getString(i));
// j should be count size, see the first for loop
string2dArray[j][i] = cursor.getString(i);
Log.i("StringPoint", string2dArray[j][i]);
}
cursor.moveToNext();
}

Error when using setmarker() from an array to GPS map

I have an array of pictures which i extract the longitude and latitude details from using exif and put them on a marker on the GPS map. Currently i am using static array which i plan to change to a dynamic array in the near future. The current code crashes my app everytime i try to set my marker, i have no idea whats wrong.
public void setMarker() {
double latitude, longitude;
String[] filepath = {"/storage/emulated/0/Pictures/CapturyGallery/CapImage1451887532716.jpg", "/storage/emulated/0/Pictures/CapturyGallery/CapImage1452411474153.jpg"};
ExifInterface intf = null;
for (int y = 0; y < filepath.length; y++) {
try {
intf = new ExifInterface(filepath[y]);
} catch (IOException e) {
e.printStackTrace();
}
if (intf != null) {
latitude = Double.parseDouble(intf.getAttribute(ExifInterface.TAG_GPS_LATITUDE));
longitude = Double.parseDouble(intf.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));
LatLng latLngCurrent = new LatLng(latitude, longitude);
MarkerOptions options = new MarkerOptions()
.position(latLngCurrent)
.title("test");
mMap.addMarker(options);
}
}
}
LOGCAT
`
01-11 15:19:30.251 32226-32226/com.sp.fyp.captury E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.sp.fyp.captury, PID: 32226
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4298)
at android.view.View.performClick(View.java:5254)
at android.view.View$PerformClick.run(View.java:21179)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6843)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4293)
            at android.view.View.performClick(View.java:5254)
            at android.view.View$PerformClick.run(View.java:21179)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:6843)
            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:1404)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.NumberFormatException: Invalid double: "1/1,18/1,30/1"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.initialParse(StringToReal.java:164)
at java.lang.StringToReal.parseDouble(StringToReal.java:282)
at java.lang.Double.parseDouble(Double.java:301)
at com.sp.fyp.captury.GPS.setMarker(GPS.java:181)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.view.View$1.onClick(View.java:4293)
            at android.view.View.performClick(View.java:5254)
            at android.view.View$PerformClick.run(View.java:21179)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:6843)
            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:1404)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)`
According to the Standard Exif Tags (as defined in the Exif 2.3 standard)
The latitude/longitude is expressed as three RATIONAL values giving
the degrees, minutes, and seconds, respectively. When degrees, minutes
and seconds are expressed, the format is dd/1,mm/1,ss/1. When degrees
and minutes are used and, for example, fractions of minutes are given
up to two decimal places, the format is dd/1,mmmm/100,0/1
Thus, when you get the latitude and logitude from the ExifInterface, you are getting values like 1/1,18/1,30/1. Of course this String values cannot be converted to double using Double.parseDouble and throw a NumberFormatException.
You can take a look at How do I convert Exif long/lat to real values? to find a converter.

Categories

Resources