【发布时间】:2016-04-25 22:06:33
【问题描述】:
当引用 EditText 对象时,我在 onClick 方法中遇到错误。
public class messageActivity extends AppCompatActivity {
EditText editText;
Button button;
Logic logic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
editText = (EditText) findViewById(R.id.editText);
button = (Button) findViewById(R.id.button6);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logic.message(editText.getText().toString());
}
});
}
}
这是我活动中 EditText 小部件的 XML:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="83dp"
android:inputType="textShortMessage"
android:editable="false" />
【问题讨论】:
-
你在哪里初始化你的逻辑变量?这似乎是这里的空指针。请张贴你的logcat