-1
我使用JavascriptInterface与我的网站进行通信的WebView应用程序,我尝试启动MapsActivity并在地图上标记点。从扩展MainActivity的类开始MapFragment活动
我加入到我的项目文件 - >新建 - >谷歌 - >谷歌地图活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = getApplicationContext();
...
mWebView.addJavascriptInterface(new WebAppInterface(this, activity, regIdFirebase, mWebView, mGoogleApiClient), "WEB2Android");
....
的WebAppInterface类有工作正常,但有一个例外很多方法:markPointsOnMap
public class WebAppInterface extends MainActivity {
Context context;
Activity activity;
String regIdFirebase;
WebView mWebView;
Object casaMarcat = null;
GoogleApiClient mGoogleApiClient;
public WebAppInterface(Context c, Activity a, String r, WebView w, GoogleApiClient p) {
context = c;
activity = a;
regIdFirebase = r;
mWebView = w;
mGoogleApiClient = p;
}
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
}
...
@JavascriptInterface
public void markPointsOnMap(String points) {
Log.d("markPointsOnMap", context.toString());
Intent i = new Intent(getApplicationContext(), MapsActivity.class);
i.putExtra("markPoints", points);
startActivity(i);
}
在网络服务器端我有这样一些简单的代码
<p>
<input type="button" value="Mark Points On Map" onClick="markPointsOnMap('47.179142,27.480926,KokoShannel;47.646331,26.254062,NaturelPiata;47.243562,26.716604,Jatakana;47.211149,27.014350,Placeholder')" />
</p>
<script type="text/javascript">
function markPointsOnMap(points) {
WEB2Android.markPointsOnMap(points);
}
</script>
而且我有这样的错误:
12-14 13:20:01.771 27100-28063/ro.nexuserp.apps W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
12-14 13:20:01.771 27100-28063/ro.nexuserp.apps W/System.err: at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:112)
12-14 13:20:01.771 27100-28063/ro.nexuserp.apps W/System.err: at ro.nexuserp.apps.utils.WebAppInterface$override.markPointsOnMap(WebAppInterface.java:116)
12-14 13:20:01.771 27100-28063/ro.nexuserp.apps W/System.err: at ro.nexuserp.apps.utils.WebAppInterface$override.access$dispatch(WebAppInterface.java)
12-14 13:20:01.771 27100-28063/ro.nexuserp.apps W/System.err: at ro.nexuserp.apps.utils.WebAppInterface.markPointsOnMap(WebAppInterface.java:0)
12-14 13:20:01.771 27100-28063/ro.nexuserp.apps W/System.err: at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
12-14 13:20:01.771 27100-28063/ro.nexuserp.apps W/System.err: at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:41)
12-14 13:20:01.771 27100-28063/ro.nexuserp.apps W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
12-14 13:20:01.771 27100-28063/ro.nexuserp.apps W/System.err: at android.os.Looper.loop(Looper.java:158)
12-14 13:20:01.771 27100-28063/ro.nexuserp.apps W/System.err: at android.os.HandlerThread.run(HandlerThread.java:61)
我想和这个变体,但相同的结果。
Intent i = new Intent(context, MapsActivity.class);