我是Java和Android编程的新手。只需要一个简单的浏览器,使用户可以访问我的论坛。我的java代码中出现了这个错误:
>> Code: Webview webview; << Simple object code at the top of app. Causes: Syntax error on token "WebView", import expected.
这是完整的.java文件代码:
package com.droidisland.app;
WebView webview;
import android.app.Activity;
public class DroidIslandActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://droidisland.net");
}
}
答案 0 :(得分:3)
您在import语句之上和类之外声明了一个WebView变量。在类声明行之后移动该声明,如此
public class DroidIslandActivity extends Activity {
WebView webview;
答案 1 :(得分:0)
In your activity you can have this code:
/*
* entry point of the application starting the index.html of PhoneGap
* */
package com.capgemini.gm.myapp;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import android.util.Log;
import com.google.analytics.tracking.android.EasyTracker;
public class MyAppMainActivitiy extends DroidGap
{
String curPhoneNumber;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("file:///android_asset/www/app/index.html",15000);
}
@Override
public void onStart() {
super.onStart();
this.appView.addJavascriptInterface(new JsInterface(), "android");
Log.d("App start activity", "interface added");
curPhoneNumber = "test";
// The rest of your onStart() code.
EasyTracker.getInstance().activityStart(this); // Add this method.
}
@Override
public void onDestroy()
{
super.onDestroy();
com.google.analytics.tracking.android.EasyTracker.getInstance().activityStop(this);
}
public class JsInterface{
public String getPhoneNumber()
{
return curPhoneNumber;
}
}
}
and in your index.html you can have this script:
<script type="text/javascript">
alert(android.getPhoneNumber());
</script>