Android-EditText在我写东西时会给出IndexOutOfBounds异常
我试图做一个简单的片段,其中有一个评级字段和一个用于评论的EditText。当我点击EditText字段并键入内容时,问题就出现了。此时,应用程序崩溃 XMLAndroid-EditText在我写东西时会给出IndexOutOfBounds异常,android,android-edittext,Android,Android Edittext,我试图做一个简单的片段,其中有一个评级字段和一个用于评论的EditText。当我点击EditText字段并键入内容时,问题就出现了。此时,应用程序崩溃 XML <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-a
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TableLayout
android:id="@+id/tableLayoutReq"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TableRow
android:id="@+id/tableRowReq1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/text_view_acceptance"
android:text="@string/label_acceptance"
android:textStyle="bold"
android:layout_gravity="center"
android:layout_weight="0.5" />
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:numStars="5"/>
</TableRow>
</TableLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/label_payment_restrictions_req"
android:text="@string/label_comment"
android:textStyle="bold"
android:gravity="start"
android:layout_marginTop="10dp" />
<EditText
android:gravity="top"
android:id="@+id/edit_text_comment_req"
android:layout_width="match_parent"
android:layout_height="200dp"
android:maxHeight="300dp"
android:paddingStart="0dp"
android:paddingLeft="0dp"
android:layout_marginTop="5dp"
android:padding="5dp"
android:background="@drawable/evaltext_bg" />
<Button
android:id="@+id/button_evaluate_service"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="10dp"
android:text="@string/button_evaluate"
style="@style/button_eval" />
</LinearLayout>
Java类
public class RequestEvaluation extends Fragment {
private RatingBar ratingBar;
private Button button;
private EditText commentsET;
public RequestEvaluation() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_request_evaluation, container, false);
commentsET = (EditText) rootView.findViewById(R.id.edit_text_comment_req);
commentsET.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_MULTI_LINE);
//addListenerOnRatingBar(rootView);
//addListenerOnButton(rootView);
return rootView;
}
public void addListenerOnRatingBar(View rootView) {
ratingBar = (RatingBar) rootView.findViewById(R.id.ratingBar);
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
}
});
}
public void addListenerOnButton(View rootView) {
ratingBar = (RatingBar) rootView.findViewById(R.id.ratingBar);
button = (Button) rootView.findViewById(R.id.button_evaluate_service);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity().getApplicationContext(),
String.valueOf(ratingBar.getRating()), Toast.LENGTH_LONG).show();
}
});
}
@Override
public void onDetach() {
super.onDetach();
}
}
有没有人有过类似的问题?或者有人知道会发生什么吗?请在edittext视图中添加以下代码
android:inputType="text"
或
这是您获得的完整日志吗?添加您在活动中使用的完整日志消息和java代码谢谢您的回复。是的,这是完整的日志。只需添加Java类,非常感谢。我正在尝试使用android:inputType=“textMultiLine”,使用此属性应用程序崩溃。但是现在,使用android:inputType=“text”和问题中的Java代码,一切正常!谢谢:)。
android:inputType="text"
android:inputType="textMultiLine"