How to solve java.lang.NoSuchMethodError: android.content.pm.PackageManager.currentToCanonicalPackageNames

2k views Asked by At

I got this exception

01-03 00:28:43.465 E/AndroidRuntime(13556): java.lang.NoSuchMethodError: android.content.pm.PackageManager.currentToCanonicalPackageNames
01-03 00:28:43.465 E/AndroidRuntime(13556):     at com.android.DL_launcher.LauncherProvider$DatabaseHelper.addAppShortcut(LauncherProvider.java:632)
01-03 00:28:43.465 E/AndroidRuntime(13556):     at com.android.DL_launcher.LauncherProvider$DatabaseHelper.loadFavorites(LauncherProvider.java:596)
01-03 00:28:43.465 E/AndroidRuntime(13556):     at com.android.DL_launcher.LauncherProvider$DatabaseHelper.onCreate(LauncherProvider.java:253)
01-03 00:28:43.465 E/AndroidRuntime(13556):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
01-03 00:28:43.465 E/AndroidRuntime(13556):     at com.android.DL_launcher.LauncherProvider.query(LauncherProvider.java:111)
01-03 00:28:43.465 E/AndroidRuntime(13556):     at android.content.ContentProvider$Transport.query(ContentProvider.java:130)
01-03 00:28:43.465 E/AndroidRuntime(13556):     at android.content.ContentResolver.query(ContentResolver.java:202)
01-03 00:28:43.465 E/AndroidRuntime(13556):     at com.android.DL_launcher.LauncherModel$DesktopItemsLoader.updateShortcutLabels(LauncherModel.java:1134)
01-03 00:28:43.465 E/AndroidRuntime(13556):     at com.android.DL_launcher.LauncherModel$DesktopItemsLoader.load_workspace(LauncherModel.java:877)
01-03 00:28:43.465 E/AndroidRuntime(13556):     at com.android.DL_launcher.LauncherModel$DesktopItemsLoader.run(LauncherModel.java:864)
01-03 00:28:43.465 E/AndroidRuntime(13556):     at java.lang.Thread.run(Thread.java:1096)

when using this method

android.content.pm.PackageManager.currentToCanonicalPackageNames(String[])

according to the dev doc

The problem happens on device Moto Milestone, with 2.1-update1 Android version.

Is this because of the modified ROM by Moto?

Any advice is appreciated.

1

There are 1 answers

1
Jens On BEST ANSWER

The method you are trying to use was introduced in 2.2 (version 8), so with a 2.1 device you're not likely to find it.

Check the build version before trying to use the class that calls that method or do a funky workaround using reflection?