2016-12-14 8 views
-1

JavascriptInterfaceを使用して自分のウェブサイトのJavaScriptと通信するWebViewアプリケーションで作業していて、マップアクトを開始してマップ上のある点をマークしようとします。MainActivityを拡張するクラスのMapFragmentでアクティビティを開始

は、私は私のプロジェクトファイルに追加 - >新規 - >グーグル - > Googleマップのアクティビティ

@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クラスは、1つの例外を除き、正常に動作している多くの方法があります。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); 

答えて

0

活動は、コンテキストオブジェクト

@JavascriptInterface 
public void markPointsOnMap(String points) { 
    Intent i = new Intent(context, MapsActivity.class); 
    i.putExtra("markPoints", points); 
    >> context.startActivity(i); << 
} 

ええとから開始する必要があります!私はこれと時間のカップルを失うと-1投票を得る:

関連する問題