EditText中的getText()有问题

http://pastebin.com/babqrrqa

Like the title says, i have problems with getting the text from a EditText.

My app crashes when reads this line :

String value = aux.getText().toString();, probably because aux.getText() is null still i have setText("lol"), at this method

 public boolean onOptionsItemSelected(MenuItem item) {  
    switch (item.getItemId()) {  
    case R.id.adicionar:  
        //Toast.makeText(this, "This is the Toast message", Toast.LENGTH_LONG).show();
        final AlertDialog.Builder alert = new AlertDialog.Builder(this);
        final EditText input = new EditText(this);

         LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         LinearLayout dialerLayout = (LinearLayout) layoutInflater.inflate(R.layout.input, null);
         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
            dialerLayout.setLayoutParams(params);


        alert.setView(dialerLayout);



        alert.setPositiveButton("Adicionar", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {


                aux = (EditText)findViewById(R.id.cadeira);
                aux.setText("lol");
                String value = aux.getText().toString();
                //String value2="TESTE";

            lista.add(value);
             adapter.notifyDataSetChanged();

            }

        });

        alert.setNegativeButton("Cancelar",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.cancel();
                    }
                });
        alert.show();



    return true;  
    default: return super.onOptionsItemSelected(item);  
    }
    }  

#0

Probably the "aux" is null.

As I suppose from your code the "cadeira" EditText is in the LinearLayout that you inflate. But when you execute "findViewByById" it searches the main layout. Thus you should try:

aux = (EditText) dialerLayout.findViewById(R.id.cadeira);

#1

This might be because of the .toString()! The result of the getText() will be a string already so the toString() might cause it to crash.

#2

there might be human error with declaring or initializing "aux", though you haven't shown the exactly error log wording, if you can detail it more, this will fix the prob faster.

推荐文章

使用PHP检查时间是否超过晚上9点

使用PHP检查时间是否超过晚上9点

推荐文章

LINQ查询-奇数结果-OrderBy

LINQ查询-奇数结果-OrderBy

推荐文章

无法将集合类作为参数传递给RIA服务

无法将集合类作为参数传递给RIA服务

推荐文章

读取属性时跨线程操作无效

读取属性时跨线程操作无效

推荐文章

FindRoot-将符号结果转换为数值

FindRoot-将符号结果转换为数值

推荐文章

Qooxdoo表单元素和getSelection()

Qooxdoo表单元素和getSelection()

推荐文章

如何捕获初始化静态成员时引发的异常

如何捕获初始化静态成员时引发的异常

推荐文章

你能静态地将同一个protobuf消息链接到多个dll,然后让这些dll一起工作吗?

你能静态地将同一个protobuf消息链接到多个dll,然后让这些dll一起工作吗?

推荐文章

学习将ASP.NET与数据库结合使用的视频资源

学习将ASP.NET与数据库结合使用的视频资源

推荐文章

routelink无法调用Actionresult。我来抓罪犯?

routelink无法调用Actionresult。我来抓罪犯?

推荐文章

添加数据源项后重新加载TTableView

添加数据源项后重新加载TTableView

推荐文章

泛型与接口

泛型与接口

推荐文章

jQuery:。每个如何引用匹配的对象

jQuery:。每个如何引用匹配的对象

推荐文章

检测加载时哪个javascript函数正在更改页面元素?

检测加载时哪个javascript函数正在更改页面元素?

推荐文章

我应该在Java项目中重用Ruby代码吗?

我应该在Java项目中重用Ruby代码吗?

推荐文章

JS到jQuery

JS到jQuery