1

In mainActivity I have method "toast1"

public class MainActivity extends Activity {

    //some imports
    public TextView txtv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    //some code
    }
    //some code
    public void toast1(String txtxt) {
        txtv = (TextView) findViewById(R.id.txtzz);
        txtv.setText(txtxt);
    }

But when toast1 method is launched, the exception is thrown:

04-18 21:16:35.185    3198-3198/com.AleXMan.democracy.standart E/InputEventReceiver﹕ Exception dispatching input event.
04-18 21:16:35.195    3198-3198/com.AleXMan.democracy.standart E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
04-18 21:16:35.195    3198-3198/com.AleXMan.democracy.standart E/MessageQueue-JNI﹕ java.lang.NullPointerException
                        at android.app.Activity.findViewById(Activity.java:1888)
                        at com.AleXMan.democracy.standart.MainActivity.toast1(MainActivity.java:48)
                        ...other

Does anyone know how to fix this?

Onik
  • 19,396
  • 14
  • 68
  • 91

0 Answers0