screen.setText是打破上使用。未捕获的厚望(组= 0xb3a539 @ 0)(Android版) [英] screen.setText is breaking on use. uncaught expection (group=0xb3a539@0) (Android)

查看:184
本文介绍了screen.setText是打破上使用。未捕获的厚望(组= 0xb3a539 @ 0)(Android版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是一个简单的事情来获得工作,在大多数其他功能和应用,我已经没有任何问题。但是这一次它不会工作。

This should be a simple thing to get working and in most other functions and applications, I've not had any issues. However this time it wont work.

该方案只是将输入从屏幕中,如果输入的是一个数字,然后添加到TextView的,如果输入的是别的然后再数字添加到TextView的和明确的输入EDITTEXT。

The program simply takes an input from the screen, if the input is a number then add to textView, if the input is anything else then numeric then add to textView and clear input editText.

在code我有低于activity_main.xml中

The code I have is below "activity_main.xml",

<TextView
        android:id="@+id/formulaDisplay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_span="4"
        android:textSize="40sp"
        android:text="@string/screenDisplay"
        android:ems="10"
        android:gravity="right"
        android:inputType="none"
        android:layout_weight="1" 
        android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
        android:id="@+id/screenDisplay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_span="4"
        android:layout_weight="1"
        android:textSize="60sp"
        android:ems="10"
        android:inputType="text"
        android:gravity="right"
        android:text="@string/screenDisplay" />

MainActivity.Java

"MainActivity.Java":

Removed code as will be flagged for plagiarism on uni submission.

的程序输入0时工作正常 - 9,然而,如果我输入/,*, - ,+等等那么它会断裂并通过一个错误。看着它,这似乎是决策意识的唯一的事情是,它可能会崩溃的EditText上,我试图更新绑定到一个onTextChange监听器,当我清除它运行文本的变化和突破。我认为这是发生了什么。

The program works fine when inputting 0 - 9, however if I input a /,*,-,+ etc then it will break and through an error. Looking at it the only thing that seems to be making sense is that it may be crashing as the EditText I am trying to update is tied to a onTextChange listener and when I clear it it runs the text change and breaks. I think that is what's happening.

logcat的

01-04 03:04:34.300: E/MessageQueue-JNI(1278): Exception in MessageQueue callback: handleReceiveCallback
01-04 03:04:34.440: E/MessageQueue-JNI(1278): java.lang.StringIndexOutOfBoundsException: length=0; index=-1
01-04 03:04:34.440: E/MessageQueue-JNI(1278):   at java.lang.String.indexAndLength(String.java:584)
01-04 03:04:34.440: E/MessageQueue-JNI(1278):   at java.lang.String.substring(String.java:1449)
01-04 03:04:34.470: W/dalvikvm(1278): threadid=1: thread exiting with uncaught exception (group=0xb3a53b90)
01-04 03:04:34.490: E/AndroidRuntime(1278): FATAL EXCEPTION: main

感谢您预先的任何帮助或建议,

Thank you in advance for any help or advice,

克里斯

推荐答案

您需要像

if(s.lenght > 0)

因为当你对你的EditText的EditText上lenght明文成​​为 0 的使用子(s.toString()长() - 1)中返回 1 针对这种情况

because when you clear Text on EditText lenght of your EditText became 0 an you use substring(s.toString().length() - 1) that return -1 for this situation

 public void onTextChanged(CharSequence s, int start, int before, int count) {
            // Creating temp string for processing
            if(s.lenght > 0)
            {
              String temp = s.toString().substring(s.toString().length() - 1);
              // Passing screen content to processInput function
              processInput(temp);
            }
        }

这篇关于screen.setText是打破上使用。未捕获的厚望(组= 0xb3a539 @ 0)(Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆