1

如您所知,自 JELLY_BEAN 以来,需要使用@JavascriptInterface可通过 JavasScriptInterface 访问的所有方法进行注释。

我在注入一些 JavaScript 时这样做,它在 API>JELLY_BEAN_MR1 的终端中运行正常。尽管如此,我在旧设备中有一个 NoClassDefFoundError 。

这是我的代码:

wvPromo.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            if(mDialog!=null && mDialog.isShowing()) mDialog.dismiss();
            view.loadUrl("javascript:(function() { "
                    + "var myEl = document.getElementById('mw-mf-main-menu-button');   "
                    + "myEl.addEventListener('click', function(){window.JSInterface.share();}, false);"
                    + "})();");
            view.addJavascriptInterface(this, "JSInterface");           
        }
    });.
...

@JavascriptInterface
public void share() {
    Log.i(getClass().getSimpleName(), "Share button");
    Intent i = Utils.shareContentIntent(this, "word", "Title");
    startActivity(i);
}

这是例外:

01-30 12:42:41.750: E/AndroidRuntime(13662): FATAL EXCEPTION: main
01-30 12:42:41.750: E/AndroidRuntime(13662): java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.cleverox.flamencomovil/com.zonaapp.flamencomovil.PromotionActivity}: com.google.inject.internal.util.$ComputationException: java.lang.NoClassDefFoundError: android.webkit.JavascriptInterface
01-30 12:42:41.750: E/AndroidRuntime(13662):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at android.os.Looper.loop(Looper.java:130)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at android.app.ActivityThread.main(ActivityThread.java:3691)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at java.lang.reflect.Method.invokeNative(Native Method)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at java.lang.reflect.Method.invoke(Method.java:507)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at dalvik.system.NativeStart.main(Native Method)
01-30 12:42:41.750: E/AndroidRuntime(13662): Caused by: com.google.inject.internal.util.$ComputationException: java.lang.NoClassDefFoundError: android.webkit.JavascriptInterface
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.FailableCache.get(FailableCache.java:50)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.MembersInjectorStore.get(MembersInjectorStore.java:65)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:950)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:957)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:943)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at roboguice.inject.ContextScopedRoboInjector.injectMembersWithoutViews(ContextScopedRoboInjector.java:243)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.zonaapp.utils.roboguice.RoboSherlockActivity.onCreate(RoboSherlockActivity.java:60)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.zonaapp.flamencomovil.PromotionActivity.onCreate(PromotionActivity.java:40)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
01-30 12:42:41.750: E/AndroidRuntime(13662):    ... 11 more
01-30 12:42:41.750: E/AndroidRuntime(13662): Caused by: java.lang.NoClassDefFoundError: android.webkit.JavascriptInterface
01-30 12:42:41.750: E/AndroidRuntime(13662):    at java.lang.reflect.Method.getDeclaredAnnotations(Native Method)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at java.lang.reflect.Method.getDeclaredAnnotations(Method.java:262)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:188)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at java.lang.reflect.AccessibleObject.getAnnotation(AccessibleObject.java:196)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.spi.InjectionPoint.getAtInject(InjectionPoint.java:466)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:664)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:356)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.MembersInjectorStore.createWithListeners(MembersInjectorStore.java:90)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.MembersInjectorStore.access$000(MembersInjectorStore.java:34)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.MembersInjectorStore$1.create(MembersInjectorStore.java:42)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.MembersInjectorStore$1.create(MembersInjectorStore.java:39)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:39)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549)
01-30 12:42:41.750: E/AndroidRuntime(13662):    ... 23 more
01-30 12:42:41.750: E/AndroidRuntime(13662): Caused by: java.lang.ClassNotFoundException: android.webkit.JavascriptInterface in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.cleverox.flamencomovil-1.apk]
01-30 12:42:41.750: E/AndroidRuntime(13662):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-30 12:42:41.750: E/AndroidRuntime(13662):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-30 12:42:41.750: E/AndroidRuntime(13662):    ... 36 more

mysql WHERE IN with group by 和 order by

我有一个main50K 行的 Innodb 表。

CREATE table main(
 id INT AUTO_INCREMENT NOT NULL,
 main_id INT NOT NULL,
 feature1 INT NOT NULL,
 feature2 INT NOT NULL,
 feature3 INT NOT NULL,
 time_repetition TIMESTAMP NOT NULL,
 rating SMALLINT NOT NULL,
 PRIMARY KEY (id),
 INDEX search(range_col1,range_col2,range_col3)
 ) engine=innodb;

POINT 1: feature*字段是一些特征。因此,在搜索过程中,用户可以检查他是否想要表中满足多个值的行,因此我需要使用INin WHERE:
feature1 IN (val1,val2,..) and feature2 IN (val1,val2,..) and feature3 IN (val1,val2,...)

POINT2:根据时间的重复对表进行非规范化。因此,我需要GROUP_CONCAT(time_repetition)在 select 和GROUP BY main_id.

POINT3:最好的价值评级首先是可取的。所以,我需要有ORDER BY rating DESC。我还考虑了每天重新计算一次评分,并按照顺序递减的评分将数据插入表中。在这种情况下,我需要拥有ORDER BY id. 不幸的是,它并没有解决问题。

所以,整个查询是: SELECT main_id, feature1, feature2, feature3, GROUP_CONCAT(time_repetition), rating FROM main WHERE feature1 IN (val1,val2,..) and feature2 IN (val1,val2,..) and feature3 IN (val1,val2,...) GROUP BY main_id ORDER BY rating LIMIT 50.

问题是查询使用临时和文件排序平均到 5K 行。例如,下面是解释的结果:

explain(select SQL_NO_CACHE * from main where feature1 in (4,5,6,7)
and feature2 IN (2,3,4,5) and feature3 IN (1,2,3,4,5) group by main_id
order by id limit 10);

+----+-------------+--------+-------+---------------+----------+---------+------+------+----------------------------------------------+
| id | select_type | table  | type  | possible_keys | key      | key_len | ref  | rows | Extra                                        |
+----+-------------+--------+-------+---------------+----------+---------+------+------+----------------------------------------------+
|  1 | SIMPLE      | main | range | search      | search | 12      | NULL | 7333 | Using where; Using temporary; Using filesort |
+----+-------------+--------+-------+---------------+----------+---------+------+------+----------------------------------------------+

如果我在索引中添加 main_id 它没有帮助。你能推荐什么?

4

0 回答 0