Question

I am having 2 main sticking point to get the following simple WebView example to compile:

  • The casting part (WebView)findViewById(R$id::webview) gives unresolved JvmIdentifiableElement

  • The anonymous class part totally doesn't work. I suppose Xtend does not support it?

Here is the source code:

package com.stackoverflow

import android.app.Activity
import android.webkit.WebView
import android.os.Bundle
import android.webkit.WebViewClient

class HelloWebViewActivity extends Activity
{
    WebView _webView

    override void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState)
        setContentView(R$layout::main)

        // Error "Couldn't resolve reference to JvmIdentifiableElement 'WebView'"
        _webView = (WebView)findViewById(R$id::webview)
        _webView.settings.javaScriptEnabled = true
        _webView.loadUrl("http://stackoverflow.com")

        // A bunch of complaints towards the anonymous class
        _webView.setWebViewClient(new WebViewClient()
        {
            override shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url)
                true
            }
        })
    }
}

and my .classpath:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="xtend-gen"/>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins" />
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry kind="con" path="org.eclipse.xtend.XTEND_CONTAINER"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>

Ideas?

Was it helpful?

Solution

1) casts in Xtend are ' as ', in your case _webView = findViewById(R$id::webview) as WebView

2) Anonymous classes are not yet supported. Consider using a closure instead if the anonymous class has a single method only (http://www.eclipse.org/Xtext/xtend/documentation/index.html#closures section on function mapping)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top