(1)error opening trace file: No such file or directory (2)
这是写的第一个程序就出现的问题,而且查询代码没有发现错误。google后得出结论:模拟器版本和android的API版本不对应,相应的进行修改就行。
?
(2)出现java.lang.NumberFormatException: unable to parse 'null' as integer
?
?出现问题查出错误出在上面代码中intent传回来的值有可能是null,就会产生转换的错误,最终修改方案是加入异常处理机制,就是使用try and catch。修改后程序运行正常。代码如下:
public class otheractivity extends Activity{
private TextView textview2 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_other);
?
textview2 = (TextView)findViewById(R.id.TextView2);
?
int oneint = 0;
int twoint = 0;?
Intent intent2 = getIntent();
String onestr = intent2.getStringExtra("one");
String twostr = intent2.getStringExtra("two");
try{
oneint = Integer.parseInt(onestr);
}
catch(Exception e){}
try{
twoint = Integer.parseInt(twostr);
}
catch (Exception e) {
// TODO: handle exception
}
int res = oneint + twoint;
String resstr = String.valueOf(res);
textview2.setText(resstr);
?
}
?
}
问题就迎刃而解了。
?
?