Home Features Docs Blog Support GitHub

java.lang.NoSuchMethodException Error using reflection on IOS side only


(Dave Kittredge) #1

Hello,

I am getting a java.lang.NoSuchMethodException on:
Method m = bean2.getClass().getMethod(methName, new Class[]{parmClass});

It works fine on Android side, only on IOS. The method reads data from a Sqlite cursor, and sets the data into a class.

The class has:
private String lastVersion;

as well as getter and setter:

public String getLastVersion() {
    return lastVersion;
}

public void setLastVersion(String lastVersion) {
    this.lastVersion = lastVersion;
}

a Utility determines the class from the sqlite column type:

/* get sqlite field type, and convert to java class */
public Class getParmClass() {
    if( getColumnType() == null ) {
        return null;
    }
    if( getColumnType().equals("TEXT")) {
        return String.class;
    }
    if( getColumnType().equals("INT") || getColumnType().equals("INTEGER")) {
        return int.class;
    }
    // SQLite does not support boolean, all booleans will be coded as TINYINT
    if( getColumnType().equals("TINYINT")) {
        return boolean.class;
    }
    if( getColumnType().equals("BOOLEAN")) {
        return boolean.class;
    }
    if( getColumnType().equals("BIGDECIMAL")) {
        return BigDecimal.class;
    }
    Log.i(LOG_TAG, MUtils.method() + "unknown column type " + getColumnType() + ", returning String.class");
    return String.class;
}

/************************/
// excerpt from DBManager

parmClass = col.getParmClass();
//offending line:  
Method m = bean2.getClass().getMethod(methName, new Class[]{parmClass});

The error:

Throwable occurred: java.lang.NoSuchMethodException: setLastVersion [class java.lang.String]
	at java.lang.Class.getMethod(Class.java:669)
	at java.lang.Class.getMethod(Class.java:648)
	at com.dkcc.iwish.shared.database.DBManager.abstractBeanFromCursor(DBManager.java:311)
	at com.dkcc.iwish.shared.database.DBManager.selectOne(DBManager.java:260)
	at com.dkcc.iwish.SplashScreenViewController.viewDidLoad(SplashScreenViewController.java:120)
	at apple.uikit.c.UIKit.UIApplicationMain(Native Method)
	at com.dkcc.iwish.Main.main(Main.java:35)

Any help or work-arounds would be appreciated.

Thanks!


#2

Check your proguard settings


(Dave Kittredge) #3

Thank you! It was proguard.
When I added these to proguard.append.cfg, it did not originally work.

-keep class com.dkcc.iwish.shared.beans.AbstractDbBean{ *; }
-keep class * extends com.dkcc.iwish.shared.beans.AbstractDbBean{ *; }

I needed to move the file into the IOS directory, and now it works!