0

I repeated the answer of this question , fail. I need to change the textView(text) that is in cardView which is located in the fragment. This is code of Fragment, i want change text in method updateTextView, but i have crash. Here's the code that I call the method with Activity

private void makeView(String wallPhoto, String wallText){

    Fragment fr =  TabFragment1.newInstance();
    getSupportFragmentManager().beginTransaction().replace(R.id.tab_fragment_1, fr, "tag").commit();
    TabFragment1 tabFragment1_text = (TabFragment1) getSupportFragmentManager().findFragmentByTag("tag");
    tabFragment1_text.updateTextView("walll");
    Log.d("", wall_text);
}

Crash looks like: java.lang.NullPointerException: Attempt to invoke virtual method 'void pc.dd.tabhost.TabFragment1.updateTextView(java.lang.String)' on a null object reference Updating: If you do as suggested by Nfear now there is no error , but the text does not change. Something like this:

private void makeView(String wallPhoto, String wallText){

    Fragment fr =  TabFragment1.newInstance();
    getSupportFragmentManager(). beginTransaction().replace(R.id.tab_fragment_1, fr, "tag").commit();
    getSupportFragmentManager().executePendingTransactions();

    TabFragment1 tabFragment1_text = (TabFragment1) getSupportFragmentManager().findFragmentByTag("tag");
    tabFragment1_text.updateTextView("walll");
    Log.d("", wall_text);
}

Called in to Activity asynktask like this:

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (!VKSdk.onActivityResult(requestCode, resultCode, data, new VKCallback<VKAccessToken>() {
        @Override
        public void onResult(VKAccessToken res) {
            _VKLogin = true;
            Toast.makeText(getApplicationContext(),"Login succes ",Toast.LENGTH_LONG).show();
            VKRequestResponse _response = new VKRequestResponse();
            _response.execute(res);
        }
        @Override
        public void onError(VKError error) {
            _VKLogin = false;

            Toast.makeText(getApplicationContext(),"Login Error",Toast.LENGTH_LONG).show();
        }

    }))
    super.onActivityResult(requestCode, resultCode, data);
}
class VKRequestResponse extends AsyncTask{

    @Override
    protected Object doInBackground(Object[] params1) {
          VKParameters _params = new VKParameters();
        _params.put(VKApiConst.COUNT, "1");
       VKRequest _vkRequest = VKApi.wall().get(_params);
        _vkRequest.executeWithListener(new VKRequest.VKRequestListener() {
            @Override
            public void onComplete(VKResponse response) {
                    parsingFromJson(response.responseString);
                    makeView(null, wall_text);
                    Toast.makeText(getApplicationContext(),"Otvet "+response.responseString,Toast.LENGTH_LONG).show();
                 super.onComplete(response);
            }

            @Override
            public void onError(VKError error) {
                Toast.makeText(getApplicationContext(),"Ошибка "+error,Toast.LENGTH_LONG).show();
                super.onError(error);
            }

        });

        return null;
    }
}
Community
  • 1
  • 1

0 Answers0