【发布时间】:2013-03-02 08:10:03
【问题描述】:
我将一个数字数组存储为字符串(我从共享首选项中获取字符串),然后尝试解析它。 但是当我使用 parseInt 时,我的应用程序崩溃了。活动 Second 由 Main 类调用。
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 错误?
-
还共享您保存在 SharedPreferences 中的最终数字数组
-
我已经更新了有问题的代码。这是 logcat imgur.com/m87QMry。这里有问题。无论我在应用程序中输入什么,它总是在 st(0,1,1,2,2,2) 中显示这 6 个值
-
知道了。现在我直接从 TextView 字符串中删除空格
标签: android integer android-activity