Прошу прощения за то что не весь код выложил . Вот мои классы где я вызываю методы: create , open - в MainActivity, getInformation - в Information
MainActivity:
package com.example.bd;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
public class MainActivity extends Activity {
private DataBaseHelper db;
int id = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
db = new DataBaseHelper(this);
try {
db.createDatabase();
} catch (IOException e) {
throw new Error("Unable to create database");
}
try {
db.openDataBase();
} catch (SQLException e) {
e.printStackTrace();
}
File database=getApplicationContext().getDatabasePath("mushrooms.db");
if (!database.exists()) {
// Database does not exist so copy it from assets here
Log.i("Database", "Not Found");
} else {
Log.i("Database", "Found");
}
ListView listView = (ListView) findViewById(R.id.lvChapters);
final String[] mushrooms = {
"1.Белый гриб" ,
"2.Моховик",
"3.Лисички" ,
"4.Опята" ,
"5.Масленок",
"6.Подберезовик"
};
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this , android.R.layout.simple_list_item_1 , mushrooms);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(MainActivity.this , Information.class);
intent.putExtra("id" , position);
intent.putExtra("title" , adapter.getItem(position));
startActivityForResult(intent , 0);
}
});
}
@Override
public void onPause() {
super.onPause();
db.close();
}
@Override
public void onResume() {
super.onResume();
try {
db.openDataBase();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Information:
package vodnik.ua.cursova;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.IOException;
import java.sql.SQLException;
/**
* Created by Admin on 25.04.2015.
*/
public class Information extends Activity{
DataBaseHelper db;
int id = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.information);
db = new DataBaseHelper(this);
try {
db.createDatabase();
} catch (IOException e) {
throw new Error("Unable to create database");
}
try {
db.open();
} catch (SQLException sqle) {
throw new Error("Unable opening database");
}
String item = getIntent().getExtras().getString("title");
id = getIntent().getExtras().getInt("id", 0);
TextView textView = (TextView) findViewById(R.id.textView1);
db.close();
}
}