tags:

views:

142

answers:

2

Hey Guys,

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.

+2  A: 

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",
                                                            "");
    }

}
Konstantin Burov
.. or change `WebView full = ` to `full = ` if you want to initialize a member variable and access it later in the code.
Andreas_D
This doesn't fix it, causes me a nullpointerException.. I've taken this code from an example also.. http://www.helloandroid.com/tutorials/webview-zoom-controls-image-sdcard
Ulkmun
@Andreas_D this also causes a nullpointer.
Ulkmun
+1  A: 

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.

Andreas_D
Sorry, but I don't really understand how I'd apply that solution to my problem, perhaps you could explain a little more?
Ulkmun