string array
(listview_array
)을 int array
으로 변환하고 숫자를 비교하려고합니다. 불행히도 앱을 실행할 때마다 앱이 다운되고 있습니다. 여기 문자열 배열을 int 배열로 변환합니다.
public class FindStop3 extends Activity implements OnItemClickListener{
private String stop,line,listview_array[],buschain,dayweek,weekly;
private int selected,day;
private TextView tvLine,tvToday,tvNext;
private ListView lv;
String currentdate = java.text.DateFormat.getDateInstance().format(Calendar.getInstance().getTime());//Get current time
String currenttime = java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime());//Get current time
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_stop3);
FindStop3.this.overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);//Lateral transition
Intent intent = getIntent();//Take data from last activity
Bundle bundle = intent.getExtras();
line=bundle.getString("Line");//Takes the previous selected line from the last activity
stop=bundle.getString("Stop");//Takes the previous selected stop from the last activity
setTitle("Selected stop: "+stop);//Modifies title
getDayOfWeek();//Gets day of week
getBusChain(line,stop,weekly);//Calls method to get the xml chain name
tvLine = (TextView) findViewById(R.id.tvLine);
tvLine.setText("Line from "+line);
tvNext = (TextView) findViewById(R.id.tvNext);
tvNext.setText("Next bus arrives at "+currenttime);
tvToday = (TextView) findViewById(R.id.tvToday);
tvToday.setText(dayweek+","+currentdate+" schedule:");
selected= getResources().getIdentifier(buschain, "array",
this.getPackageName());//Lets me use a variable as stringArray
listview_array = getResources().getStringArray(selected);
lv = (ListView) findViewById(R.id.lvSchedule);
lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, listview_array));
getNextBus();
}
그리고 여기에 변환 할 수있는 방법입니다 : 메소드가 실행되지 않는 경우
이public void getNextBus() {
//Converts listview_array into an integer array
int myar[]=new int[listview_array.length];
for(int i=0;i<listview_array.length;i++){
myar[i]=Integer.parseInt(listview_array[i]);
}
, 응용 프로그램이 완벽하게 작동은. 값은 다음과 같이 xml 파일에서 가져옵니다.
<string-array name="Schedule">
<item>05:40</item>
<item>06:00</item>
<item>06:16</item>
<item>06:28</item>
<item>06:40</item>
<item>07:16</item>
<item>07:29</item>
<item>07:43</item>
<item>07:55</item>
<item>08:07</item>
<item>08:22</item>
</string-array>
누구에게 문제가 될 수 있는지 아이디어를 줄 수 있습니까?
감사합니다.
LogCat은 무엇이라고 말합니까? – pedromss
"05:40"또는 "05"와 "40"을 Interger.parseInt에 전달합니까? "05:40"을 전달하면 작동하지 않습니다. –