In my program I have a list like this picture
so you can see that each list have 2 lines and 1 button so I call each button from each list like this
public void buttonGetClicked(View v){
db.open();
LinearLayout linearLayout = (LinearLayout)v.getParent();
TextView idRow = (TextView) linearLayout.getChildAt(4);
Toast.makeText(Im_SensShow.this, idRow.getText(), Toa开发者_开发知识库st.LENGTH_SHORT).show();
and result is if I click button in list one , it will display "1" and if I click button in list two, it will display "2"
but the thing that I need is get text from database to read in TTS function
(for example in this picture : if press button in list one ,TTS will make sound like "Do you have a room" and if I press button in list two, TTS will make sound like "Do you")
and I've coded database already like this
public Cursor getSound(String rowId) {
return db.query(IM_SENS_TABLE, new String[] {
KEY_IM_SENS_ID,
KEY_IM_SENS},
KEY_IM_SENS_ID + "="+ rowId,
null, null, null, null, null);
}
I try to write like this
public void buttonGetClicked(View v){
db.open();
LinearLayout linearLayout = (LinearLayout)v.getParent();
TextView idRow = (TextView) linearLayout.getChildAt(4);
Cursor cc = cursor;
cc = db.getSound(idRow.getText().toString());
startManagingCursor(cc);
String sp=cc.getString(cc.getColumnIndexOrThrow(DBAdapter.KEY_IM_SENS));
onInit(sp);
}
public void onInit(String speech) {
tts.setLanguage(Locale.ENGLISH);
tts.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}
but It force close
please help
I think your code is throwing a CursorIndexOutOfBoundsException
. Initially I suspected getColumnIndexOrThrow()
, however this should throw an IllegalArgumentException
if the column does not exist.
As such I'm thinking that the error may lie in your db.getSound()
call. Check the code in this method to see if anything can throw a CursorIndexOutOfBoundsException
. You could also either step through the code using a debugger or add some Log.d()
output to narrow down the cause of the issue.
精彩评论