我想在我的项目中实现一个搜索栏,javascript代码是:
seekBarR.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int progressChangedValue = 0;
WebView myWeb;
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progressChangedValue = progress;
myWeb.loadUrl("javascript:polyhedronGenerator.radius='+progress+'");
myWeb.loadUrl("javascript:polyhedronGenerator.Redraw(0)");
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(nav_two_hard.this, "Seek bar progress is :" + progressChangedValue,
Toast.LENGTH_SHORT).show();
}
});
javascript代码为:
polyhedronGenerator.radius=100
polyhedronGenerator.Redraw(2)
多面体的半径应该通过搜索条的移动来改变。
我得到了这样的错误:
08-08 11:18:36.114 26557-26557 / com.example.jzhu26.testui E / InputEventReceiver:异常调度输入事件。 08-08 11:18:36.114 26557-26557 / com.example.jzhu26.testui E / MessageQueue-JNI:MessageQueue回调中的异常:handleReceiveCallback 08-08 11:18:36.116 26557-26557 / com.example.jzhu26.testui E / MessageQueue-JNI:java.lang.NullPointerException:尝试调用虚方法' void android.webkit.WebView.loadUrl(java .lang.String)'在null对象引用上 在com.example.jzhu26.testui.nav_two_hard $ 1.onProgressChanged(nav_two_hard.java:96) 在android.widget.SeekBar.onProgressRefresh(SeekBar.java:93) 在android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:1303) 在android.widget.ProgressBar.refreshProgress(ProgressBar.java:1315) 在android.widget.ProgressBar.setProgress(ProgressBar.java:1361) 在android.widget.AbsSeekBar.trackTouchEvent(AbsSeekBar.java:666) 在android.widget.AbsSeekBar.onTouchEvent(AbsSeekBar.java:579) 在android.view.View.dispatchTouchEvent(View.java:9300) 在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) 在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) 在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) 在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) 在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) 在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) 在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) 在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) 在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) 在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) 在com.android.internal.policy.PhoneWindow $ DecorView.superDispatchTouchEvent(PhoneWindow.java:2403) 在com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1737) 在android.app.Activity.dispatchTouchEvent(Activity.java:2771) 在android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:63) 在com.android.internal.policy.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:2364) 在android.view.View.dispatchPointerEvent(View.java:9520) 在android.view.ViewRootImpl $ ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4230) 在android.view.ViewRootImpl $ ViewPostImeInputStage.onProcess(ViewRootImpl.java:4096) 在android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:3642) 在android.view.ViewRootImpl $ InputStage.onDeliverToNext(ViewRootImpl.java:3695) 在android.view.ViewRootImpl $ InputStage.forward(ViewRootImpl.java:3661) 在android.view.ViewRootImpl $ AsyncInputStage.forward(ViewRootImpl.java:3787) 在android.view.ViewRootImpl $ InputStage.apply(ViewRootImpl.java:3669) 在android.view.ViewRootImpl $ AsyncInputStage.apply(ViewRootImpl.java:3844) 在android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:3642) 在android.view.ViewRootImpl $ InputStage.onDeliverToNext(ViewRootImpl.java:3695) 在android.view.ViewRootImpl $ InputStage.forward(ViewRootImpl.java:3661) 在android.view.ViewRootImpl $ InputStage.apply(ViewRootImpl.java:3669) 在android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:3642) 在android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5922) 在android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5896) 在android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5857) 在android.view.ViewRootImpl $ WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6025) 在android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185) 在... 08-08 11:18:36.117 26557-26557 / com.example.jzhu26.testui D / AndroidRuntime:关闭VM
任何人都可以帮助我吗?谢谢!
答案 0 :(得分:0)
您忘记在WebView中实例化了!使用构造函数来制作如下:
WebView myWeb = new WebView(getApplicationContext());