我在字符串转换中遇到问题,我通过意图传递一个值并通过捆绑访问,现在我想转换为整数,但它显示强制停止......
主要活动代码:
btn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent in=new Intent(MainActivity.this,second.class);
in.putExtra("id", "12");
startActivity(in);
}
});
第二个活动代码:
Bundle extras = getIntent().getExtras();
id=extras.getString("id");
btn=(Button)findViewById(R.id.button1);
tv=(TextView)findViewById(R.id.value);
btn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
int myid=Integer.parseInt(id);
//tv.setText(myid);
Toast.makeText(getApplicationContext(), myid,Toast.LENGTH_SHORT).show();
}
});
LogCat:>
09-25 18:21:52.045: E/AndroidRuntime(1555): FATAL EXCEPTION: main
09-25 18:21:52.045: E/AndroidRuntime(1555): android.content.res.Resources$NotFoundException: String resource ID #0xc
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.content.res.Resources.getText(Resources.java:230)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.widget.Toast.makeText(Toast.java:265)
09-25 18:21:52.045: E/AndroidRuntime(1555): at com.example.convert.second$1.onClick(second.java:34)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.view.View.performClick(View.java:4204)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.view.View$PerformClick.run(View.java:17355)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.os.Handler.handleCallback(Handler.java:725)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.os.Handler.dispatchMessage(Handler.java:92)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.os.Looper.loop(Looper.java:137)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-25 18:21:52.045: E/AndroidRuntime(1555): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 18:21:52.045: E/AndroidRuntime(1555): at java.lang.reflect.Method.invoke(Method.java:511)
09-25 18:21:52.045: E/AndroidRuntime(1555): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-25 18:21:52.045: E/AndroidRuntime(1555): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-25 18:21:52.045: E/AndroidRuntime(1555): at dalvik.system.NativeStart.main(Native Method)