我正在存储一个数组作为字符串(我从共享首选项中获取字符串),然后尝试解析它。 但是,当我使用parseInt我的应用程序崩溃。活动Second由Main类调用。在Android中解析错误
public class Second extends Activity {
public int[] x = new int[50];
public int[] y = new int[50];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
SharedPreferences data= getSharedPreferences("data",0);
SharedPreferences.Editor editor= data.edit();
StringBuilder str = new StringBuilder();
str.append(data.getString("val", "0")).append(",").append(getIntent().getExtras().getString("thetext"));
String end = str.toString();
editor.putString("val", end);
editor.commit();
//EditText et1= (EditText) findViewById(R.id.editText2);
//et1.
String savedString = data.getString("val", "0");
savedString.replaceAll("\\s","");
String[] st = savedString.split(",");
int i;
for(i=0;i<st.length;i++){
st[i].trim();
Log.d("Debug" , "st["+i+"] = "+st[i]);
x[i] = Integer.valueOf(st[i]);
y[i]=i;}
}
public void lineGraphHandler (View view)
{
LineGraph line = new LineGraph();
Intent lineIntent = line.getIntent(this);
startActivity(lineIntent);
}
}
它在哪里的问题呢?
什么是logcat错误? – 2013-03-14 04:52:54
也共享最终号码你在SharedPreferences中保存的数组 – 2013-03-14 04:54:00
我已经更新了有问题的代码。这是http://imgur.com/m87QMry的logcat。这里有点可疑。无论我在应用中输入什么内容,它总是显示st(0,1,1,2,2,2) – user0000007 2013-03-14 06:06:09