-1

我是 eclipse 的新手,我有一个项目可以使用 textview 添加和编辑姓名、年龄等,可能与联系人列表相同

parseint在这里我有 3 个类.. 1 个用于 arraylist 数据 1 个用于视图持有者,最后一个是我的活动问题是当我使用 parseint 作为年龄时.. 如果我使用字符串,当我使用 a和之后没有任何问题我填写姓名和年龄,然后按添加按钮,它显示应用程序已意外停止..

这是一些代码

public void Save(View view){
        @SuppressWarnings("unchecked")

        ArrayAdapter<Data> adapter = (ArrayAdapter<Data>)getListAdapter();

        EditText Name = (EditText)findViewById(R.id.Name);
        EditText Age = (EditText)findViewById(R.id.Age);

        String name = Name.getText().toString();
        int age = Integer.parseInt(Age.getText().toString());

        if (edit)
        {
            Data temp = adapter.getItem(position);
            temp.setData(name,age);
        }
        else
        {
            Data temp = new Data(name, age);
            friends.add(temp);
        }
        viewflipper.showNext();
    }

如果我使用字符串它的工作,int age = Integer.parseInt(Age.getText().toString());我不知道该代码有什么问题并且我已经将我的文本视图的 xml 更改为这个 android:inputType="number" >,但它也是同样的错误

这是日志猫

06-15 08:25:56.419: W/KeyCharacterMap(6003): No keyboard for id 0
06-15 08:25:56.419: W/KeyCharacterMap(6003): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-15 08:25:58.619: W/ResourceType(6003): No package identifier when getting value for resource number 0x0000000c
06-15 08:25:58.619: D/AndroidRuntime(6003): Shutting down VM
06-15 08:25:58.629: W/dalvikvm(6003): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-15 08:25:58.650: E/AndroidRuntime(6003): FATAL EXCEPTION: main
06-15 08:25:58.650: E/AndroidRuntime(6003): android.content.res.Resources$NotFoundException: String resource ID #0xc
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.content.res.Resources.getText(Resources.java:201)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.widget.TextView.setText(TextView.java:2857)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at itnb.week.Exercise6Activity$DataAdapter.getView(Exercise6Activity.java:165)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.widget.AbsListView.obtainView(AbsListView.java:1430)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.widget.ListView.onMeasure(ListView.java:1127)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.view.View.measure(View.java:8313)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.view.View.measure(View.java:8313)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.view.View.measure(View.java:8313)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.view.View.measure(View.java:8313)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.view.View.measure(View.java:8313)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.os.Looper.loop(Looper.java:123)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at android.app.ActivityThread.main(ActivityThread.java:3683)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at java.lang.reflect.Method.invokeNative(Native Method)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at java.lang.reflect.Method.invoke(Method.java:507)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-15 08:25:58.650: E/AndroidRuntime(6003):     at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

3

采用

 textview.setText(Integer.toString(age));
于 2012-06-24T18:15:52.720 回答
1

我认为您试图将文本设置为 int。我的意思是你试过textview.setText(age);

所以你必须使用字符串,比如textview.setText(" "+age);

于 2012-06-24T18:12:09.473 回答