Android 输入字符输出ascii码,编译没问题但是运行时崩溃

mozpp 2014-08-22 10:59:08
public class Activity1 extends Activity {

public static int char2ASCII(char c) {
return (int) c;
}
public static int[] string2ASCII(String s) {// 字符串转换为ASCII码
if (s == null || "".equals(s)) {
return null;
}

char[] chars = s.toCharArray();
int[] asciiArray = new int[chars.length];

for (int i = 0; i < chars.length; i++) {
asciiArray[i] = char2ASCII(chars[i]);
}
return asciiArray;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity1);

Button button1=(Button)this.findViewById(R.id.button1);
final EditText editText1=(EditText)findViewById(R.id.editText1);



button1.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
String a=editText1.getText().toString();
Intent intentRef=new Intent();
intentRef.setClass(Activity1.this, Activity2.class);

Bundle bundle = new Bundle();
bundle.putIntArray("a", string2ASCII(a));
intentRef.putExtras(bundle);

startActivity(intentRef);
Activity1.this.finish();
}
}
);
}
}


public class Activity2 extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity2);

Bundle bundle = this.getIntent().getExtras();
int[] b = bundle.getIntArray("a");
int c= b[0]%10;

TextView textview =(TextView) findViewById(R.id.textView1);
textview.setText(c) ;
}
}
...全文
230 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
skgary 2014-08-22
  • 打赏
  • 举报
回复
引用 6 楼 heaimnmn 的回复:
编译出现问题,说资源文件有问题
其实我也一开始也是这么认为的。。。 但是,实际上他setText传了一个int进去。。。但他想要的应该是想显示int的值。。。
哎,真难 2014-08-22
  • 打赏
  • 举报
回复
编译出现问题,说资源文件有问题
skgary 2014-08-22
  • 打赏
  • 举报
回复
异常那行:textview.setText(""+c) ;或textview.setText(Intege.valueOf(c)) ;
skgary 2014-08-22
  • 打赏
  • 举报
回复
clean&rebuild一下
mozpp 2014-08-22
  • 打赏
  • 举报
回复
引用 1 楼 skgary 的回复:
异常日志呢?
mozpp 2014-08-22
  • 打赏
  • 举报
回复
求大神求大神
skgary 2014-08-22
  • 打赏
  • 举报
回复
异常日志呢?

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧