Android Question EditText odd behavior

Shaun

Member
Licensed User
Longtime User
Hi,

I have a layout with an EditText box and a webview on it. It want the textbox to show the URL of the webpage in the webview.

The webview shows fine, but when I do, EditText1.text = webview1.url I get a nullpointerexception error. If I put the URL into a variable, then assign it to the EditText, I get the same error.

This code pukes:
B4X:
Activity.LoadLayout("Settings")
WebViewChoose.LoadUrl("http://www.google.com/")
EditTextURL.Text = WebViewChoose.url

But if I do this:
B4X:
Activity.LoadLayout("Settings")
WebViewChoose.LoadUrl("http://www.google.com/")
EditTextURL.Text = "http://www.google.com/"

It works fine.

Here is the error:


EditTextURL.Text = WebViewChoose.url
java.lang.NullPointerException


at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:38)
at b4a.example.activitysettings._activity_create(activitysettings.java:254)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at b4a.example.activitysettings.afterFirstLayout(activitysettings.java:89)
at b4a.example.activitysettings.access$100(activitysettings.java:16)
at b4a.example.activitysettings$WaitForLayout.run(activitysettings.java:74)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)


at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

Any ideas what I'm doing wrong?
 

stevel05

Expert
Licensed User
Longtime User
I haven't used webview much but it may be that the url isn't returned until the page is loaded. Try creating a PageFinished sub (see the documentation) and update the textview in there.
 
Upvote 0
Top