4

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?

kizzx2
  • 18,775
  • 14
  • 76
  • 83

1 Answers1

5

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)

Jan Koehnlein
  • 211
  • 1
  • 2
  • Thanks for the answer! They addressed my issues asked but unfortunately, I am still not able to use Xtend for Android development yet because it will always cause the ["duplicate content in APK" error](http://stackoverflow.com/questions/2934185/how-to-fix-error-generating-final-archive-duplicate-entry-androidmanifest-xml). Currently the only solution seems to be using Maven's `extractDuplicate` which I don't really want to do. – kizzx2 Jan 30 '12 at 09:47