【问题标题】:error get string to array string & string to array int错误获取字符串到数组字符串和字符串到数组 int
【发布时间】:2016-06-11 22:01:40
【问题描述】:

我试图通过按下应用程序按钮并将整数转换为字符串来在编辑文本中编写类似 1 + 1 的内容,以便将它们放在整数的其余部分 ex: 11 not 1+1 (=2 ) 这行代码出现错误“FATAL EXCEPTION” 按任意数字键时

N[ii] = Integer.parseInt(stringNumber);

在按下 Sins x,+,- 按钮时显示计算方法中也会出现“致命异常”错误

private void insertOrCheckNumber() {
    if (End == 0) {
        ii++;
    } else if (u == 0) {
        N = new int[ii];
        stringNumber = stringNumber + String.valueOf(num);
        displayCalculations(stringNumber);
        N[ii] = Integer.parseInt(stringNumber);
    }
    if (u == 1) {
        Sins = new String[iii];
        displayCalculations(Sins[iii]);
    }

}
private void clickNumber(int cN) {
    u = 0;
    num = cN;
    insertOrCheckNumber();
}

private void displayCalculations(String txt) {
    Calcs = String.valueOf(showCalcs.getText());
    showCalcs.setText(Calcs + " " + txt);
}

【问题讨论】:

    标签: android arrays string android-edittext int


    【解决方案1】:

    在你的活动中

    私有 ListView 列表视图;

    onCreate

    listView = (ListView) findViewById(R.id.listView);  
    ArrayList<> finalN = new ArrayList<y>;
    customAdapter = new listAdapter(this,R.layout.listview_example, finalN);
            listView.setAdapter(customAdapter);
    
    public class listAdapter extends ArrayAdapter<>
            {
                public listAdapter(Context context, int resource, List<> objects) {
                super(context, resource, objects);
            }
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
                Display display = wm.getDefaultDisplay();
                Point size = new Point();
    
                View v = convertView;
                if (v == null) {
                    LayoutInflater vi;
                    vi = LayoutInflater.from(getContext());
                    v = vi.inflate(R.layout.listview_example, null);
                }
                   //Setting the value to the textfields
                return v;
            }
    

    如果你想要我的完整代码,请询问,我会发送它;)

    【讨论】:

    猜你喜欢
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-14
    • 2014-10-24
    • 2013-04-27
    • 2018-05-03
    • 1970-01-01
    相关资源
    最近更新 更多