Skizit
Skizit

Reputation: 44862

Webview not working?

I've got the following method...

public class Image extends Activity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);

/* Using WebView to display the full-screen image */
WebView full = (WebView)findViewById(R.id.webview);

/* Set up the Zoom controls */
FrameLayout mContentView = (FrameLayout) getWindow().
getDecorView().findViewById(android.R.id.content);
final View zoom = this.full.getZoomControls();
mContentView.addView(zoom, ZOOM_PARAMS);
zoom.setVisibility(View.VISIBLE);

/* Create a new Html that contains the full-screen image */
String html = new String();
html = ("<html><center><img src=\"1276253554007.jpg\"></html>" );

/* Finally, display the content using WebView */
full.loadDataWithBaseURL("file:///sdcard/DCIM/Camera/",
                                                        html,
                                                        "text/html",
                                                        "utf-8",
                                                        "");
}

}

R.id.webview refrences...

 <?xml version="1.0" encoding="utf-8"?>
 <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

But I'm getting a full cannot be resolved or is not a field compile error, but full is defined as.. WebView full = (WebView)findViewById(R.id.webview); anyone have any idea why this isnt working?

Thanks.

Upvotes: 0

Views: 3020

Answers (2)

Konstantin Burov
Konstantin Burov

Reputation: 69238

Remove "this." prefix from the full variable usages. It looks like you're trying to access method local variable, while "this." keyword is intended for accessing member variables.

Here is modified code sample which compiled and runs just fine for me.

    public class Image extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);

    /* Using WebView to display the full-screen image */
    WebView full = (WebView)findViewById(R.id.webview);

    /* Set up the Zoom controls */
    FrameLayout mContentView = (FrameLayout) getWindow().
    getDecorView().findViewById(android.R.id.content);
    final View zoom = full.getZoomControls();
    mContentView.addView(zoom);
    zoom.setVisibility(View.VISIBLE);

    /* Create a new Html that contains the full-screen image */
    String html = new String();
    html = ("<html><center><img src=\"1276253554007.jpg\"></html>" );

    /* Finally, display the content using WebView */
    full.loadDataWithBaseURL("file:///sdcard/DCIM/Camera/",
                                                            html,
                                                            "text/html",
                                                            "utf-8",
                                                            "");
    }

}

Upvotes: 2

Andreas Dolk
Andreas Dolk

Reputation: 114847

Your comments to the other answer reminded me of a similiar problem I once read on SO. Guess it's the same: you're looking for WebView in the Actitvity view while I guess it's actually declared in a dialog view... The linked answer solved the other OP's problem.

Upvotes: 1

Related Questions