R.raw.content1_1 is a int. there are a text to store all the content's path. when I use the buffered reader to read the path , it cannot work. But if I don't parse String to int, it do well. when i want to display the content, i just find the path is string "R.raw.content1_1" i get from database.
public void addContent(){
new Thread(new Runnable() {
@Override
public void run() {
try {
SQLiteDatabase db = dbHelper.getWritableDatabase();
BufferedReader localBufferReader = new BufferedReader(
new InputStreamReader(getResources().openRawResource(
R.raw.title1)));
BufferedReader localBufferReader1 = new BufferedReader(
new InputStreamReader(getResources().openRawResource(
R.raw.content_path1)));
BufferedReader localBufferReader2 = new BufferedReader(
new InputStreamReader(getResources().openRawResource(
R.raw.video_path1)));
for (int i = 1; i < 97; i++) {
String title = localBufferReader.readLine();
// int content_path =Integer.parseInt(localBufferReader1.readLine());
String content_path1 = localBufferReader1.readLine();
//the content_path1 cannot parse to int.
int content_path = Integer.parseInt(content_path1);
String video_path = localBufferReader2.readLine();
if (title == null) {
localBufferReader.close();
localBufferReader1.close();
localBufferReader2.close();
break;
}
ContentValues cv = new ContentValues();
cv.put("id", i);
cv.put("title", title);
cv.put("content", content_path);
cv.put("path", video_path);
db.insert("book1", null, cv);
}
Log.v("successful","777hhaa");
db.close();
}catch (Exception e){
e.printStackTrace();
}
}
if i store the path is string in database, openRawResource(int)...cant open the raw resource
private void displayContent(){
String course = mainActivity.getCourse();
book = mainActivity.getBook();
String columns = "content";
Cursor cursor = db.query(book, new String[] {columns}, "title=?", new String[] {course}, null, null, null, null);
while (cursor.moveToNext()) {
cursor.getString(cursor.getColumnIndex("content"));
content = cursor.getString(0);
//content = Integer.parseInt(content1);
int content1 = Integer.parseInt(content,16);
textView.setText(content1);
}
cursor.close();
/*
try{
InputStream inputStream = getResources().openRawResource(content);
InputStreamReader inputReader = new InputStreamReader(inputStream, "UTF-8");
BufferedReader bufferedReader = new BufferedReader(inputReader);
textView.setText(bufferedReader.readLine());
}catch (Exception e){
e.printStackTrace();
}*/
}
all the error message :
AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.iuuu.listenstudy, PID: 2721
java.lang.NumberFormatException: Invalid int: "R.raw.content1_1"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:410)
at java.lang.Integer.parseInt(Integer.java:367)
at com.example.iuuu.listenstudy.ContentFragment.addContent(ContentFragment.java:58)
at com.example.iuuu.listenstudy.ContentFragment.onCreateView(ContentFragment.java:42)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)