且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

转移一个字符串,新活动+字符串转换为整数

更新时间:2023-01-08 16:24:07

它打破,而试图为空字符串转换为整数。什么是错的,当通过你的字符串到下一个活动。尝试通过你的字符串额外通过捆绑来代替:

It's breaking while trying to convert an empty string to an integer. Something is wrong while passing your string to the next activity. Try passing your string extra through a bundle instead:

Bundle b = new Bundle();
b.putString("key", string);
//put into your intent
yourIntent.putExtras(b);

然后把它在你的下一个活动:

Then get it in your next activity:

Bundle b = getIntent().getExtras();
String s = b.getString("key");

您也确实需要切换你TextViews你的声明,当你进行设置。你不能设置他们,如果他们还没有宣布。

You also do need to switch your declarations of your TextViews and when you set them. You can't set them if they are not yet declared.

编辑:还有一件事。我假设你的 的要输入到该的EditText整数。你应该设置inputType就可以了,如果你还没有。

One more thing. I'm assuming you only want integers typed into that EditText. You should set the inputType on it, if you haven't already.

编辑2:不要觉得迟钝,我们都是初学者在一个点!首先,请尝试使用一个包,看看有什么你输入到你的EditText正确传递到下一个活动。

Edit 2: Don't feel retarded, we were all beginners at one point! Firstly, try using a bundle and see if what you type into your EditText is properly passed to the next activity.

二,将 inputType 的EditText 在XML文件中。如果是这样的安卓inputType =号

Second, you set the inputType for the EditText in your XML file. Should be something like android:inputType="number".

该声明是这些行:

column1tv = (TextView) findViewById(R.id.column1text);

您正在创建一个对象,你TextViews。然后,你在这里设置它们:

You're creating an object for your TextViews. Then, you set them here:

column1tv.setText(counter1);

您必须创建和实例化对象之前,你可以用它做任何事情。

You must create and instantiate the object before you can do anything with it.

编辑3: 好吧,从您发布的截图中,我收集了以下内容:

Edit 3: Okay, from the screenshot you posted, I gathered the following:

第一 - 您正在创建的对象计数器1,计数器等。,但你永远实例他们任何东西。这可能是在那里你得到你的最新异常。

First- You're creating the objects counter1, counter2, etc.. but you're never instantiating them with anything. Which is probably where you're getting your latest exception.

二 - 你得到的的String = b.getString(笑)警告; ,因为它是一个未使用的本地变量。 (请在Eclipse中的问题选项卡,你会看到你在你的code什么的警告/问题)。你不这样做与从previous活动传递的字符串值的东西。

Second- You're getting the warning on the String s = b.getString("lol"); because it's an unused local variable. (Check the problems tab in Eclipse and you'll see what the warnings/problems you have in your code). You're not doing anything with the string value that was passed from the previous activity.