HelloWebView ///R.id.webview klappt nicht

K

kabummski

Fortgeschrittenes Mitglied
18
Hallo ich nochmal.

Ich will jetzt die HelloWebView App Programmieren, doch er meckert bei "R.id.webview"

Habe schon einige Dinge ausprobiert, wahrscheinlich ist die Lösung auch ganz Leicht, doch ich komme nicht drauf -.-

HelloWebView.java
package com.example.hellowebview;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import com.example.hellowebview.R;


public class HelloWebView extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
}
}

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>

<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
/>
</LinearLayout>


R.java
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/

package com.example.hellowebview;


public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}


Warum kann ich nicht auf die R.java und somit auf "id" zugreifen?

Hier die fehlermeldung;
id cannot be resolved or is not a field


DANKE IM VORRAUS
 
Dein main.xml ist kein valides XML-File. Wenn Du es nicht nachvollziehen kannst, lies noch ein wenig über XML.
 
Hallo,

JanF hat recht.
So weit ich mich erinnere, muss jedes Tag geschlossen werden, z.B.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
...
</LinearLayout> <!-- Tag geschlossen -->
Die anderen Tags sollten auch "geschlossen werden".
 
coolsmile schrieb:
Hallo,

JanF hat recht.
So weit ich mich erinnere, muss jedes Tag geschlossen werden, z.B.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
...
</LinearLayout> <!-- Tag geschlossen -->
Die anderen Tags sollten auch "geschlossen werden".

<DiesesTagSchließtSichSelbst />
Das ist gültig, allerdings ist da ein XML Element, dass 2 mal geschlossen wird. Das meinte JanF.
 

Ähnliche Themen

SaniMatthias
Antworten
19
Aufrufe
947
swa00
swa00
O
Antworten
15
Aufrufe
2.966
ORHUX
O
D
Antworten
3
Aufrufe
452
jogimuc
J
Zurück
Oben Unten