在mainActivity中我有方法" 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);
}
但是当启动toast1方法时,抛出异常:
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
有谁知道如何解决这个问题?