Faced the problem of opening the activation. I need to, when clicking on a link in WebView, open a new activation. I do so

................... arhivView.setWebViewClient(new myWebViewClient()); .................. 

where is the class myWebViewClient

  public class myWebViewClient extends WebViewClient { @Override//тут отлавливается нажатие на ссылку public boolean shouldOverrideUrlLoading(WebView view, String url) { trunsitionTo tr = new trunsitionTo(); tr.startMaps(convertStringToByte(getStringArr(url))); return true; } ... } 

and the trunsitionTo class (with only one method, it was written due to the lack of multiple inheritance in Java)

 public class trunsitionTo extends Activity { public void startMaps(byte[] info) { Intent intent = new Intent(this,NavigatingActivity.class);//на этой строке все вылетает intent.putExtra("allBalloon",false); intent.putExtra("infoBuilding",info); startActivity(intent); } } 

but the application does not work. Already I do not know what to do.

Log:

 04-01 13:09:26.536: ERROR/AndroidRuntime(915): java.lang.NullPointerException at android.content.ContextWrapper.getPackageName(ContextWrapper.java:120) at android.content.ComponentName.<init>(ComponentName.java:75) at android.content.Intent.<init>(Intent.java:2551) at Vesna.Upi.UseIT.trunsitionTo.startMaps(trunsitionTo.java:25) at Vesna.Upi.UseIT.myWebViewClient.shouldOverrideUrlLoading(myWebViewClient.java:20) at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:193) at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:304) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4363) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) at dalvik.system.NativeStart.main(Native Method) 

The issue is resolved! Now it looks like

 public class NewsActivity extends Activity { private WebView arhivView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.news_page); arhivView.setWebViewClient(new myWebViewClient(this)); ... ... ... } ... ... ... //этот класс располагается внутри класса NewsActivity, чтобы было наследование от Activity private class myWebViewClient extends WebViewClient { Context mContext; myWebViewClient(Context context) { mContext = context; } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { byte[] m = convertStringToByte(getStringArr(url)); startMaps(convertStringToByte(getStringArr(url))); return true; } public void startMaps(byte[] info) { Intent intent = new Intent(mContext,NavigatingActivity.class); //intent.setClass(this,NavigatingActivity.class); intent.putExtra("allBalloon",false); intent.putExtra("infoBuilding",info); startActivity(intent); } } } 

    2 answers 2

    Something like something ugly looks like a code. First, follow the convention of names, and secondly, with regards to your problem, all activations should open through the intent and not like this:

    trunsitionTo tr = new trunsitionTo ();

    then your context is initialized, I would suggest to keep the context in the trunsitionTo class and not to inherit the class from the Activity

    • If I could open through the intent in first grade, I would do it. As you can see, the first class is inherited from WebViewClient, which means it cannot be inherited from Activity => the startActivity (intent) method cannot be called directly, therefore, it was necessary to pervert. If you can offer another way to open a new activation by clicking on the link in WebView, then I will be only too happy :) - andreich
    • public class trunsitionTo {private Context mContext; public trunsitionTo (Context context) {mContext = context; } public void startMaps (byte [] info) {Intent intent = new Intent (mContext, NavigatingActivity.class); intent.putExtra ("allBalloon", false); intent.putExtra ("infoBuilding", info); startActivity (intent); }} - kENNAAAAA
    • wake up context from source activation - kENNAAAAA
    • Something is not visible that you did. But I found my cant, mContext.startActivity (intent) should be - kENNAAAAA
    • so, I tried it, it didn't work out for me, so I removed it. now wrote as you suggested. public void startMaps (byte [] info) {Intent intent = new Intent (mContext, NavigatingActivity.class); //intent.setClass (this,NavigatingActivity.class); intent.putExtra ("allBalloon", false); intent.putExtra ("infoBuilding", info); mContext.startActivity (intent); } but nothing cried, the error is the same - andreich
     public class trunsitionTo extends Activity 

    where is the overridden onriate method?

    • so what should change? @Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); } I added it, but everything still crashes - andreich
    • post error log =) - Gorets
    • ok i added - andreich