android


app crashed when onCreate func is running in SQLite


I'm tring to rum my app. I want to insert into my DB 2 info but when I call insertContact and it goes to onCreate it crashed. Can someone find my mistake here?
I am using SQLiteDatabase in anroid
Thank you and have a nice day!
This is my DBHelper class
public class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "CategoriesDB.db";
private static final int DATABASE_VERSION = 1;
private static final String COLUMN_ID = "id";
private static final String CATEGORY_ID = "id";
private static final String CATEGORY_TABLE_NAME = "category";
private static final String CATEGORY_NAME = "category_name";
private static final String CATEGORY_IMAGE = "category_image";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table if not exists "
+ CATEGORY_TABLE_NAME + "(" +
CATEGORY_ID + " integer primary key autoincrement, " +
CATEGORY_NAME + " text not null, " +
CATEGORY_IMAGE + " text not null)");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + CATEGORY_TABLE_NAME);
onCreate(db);
}
public boolean insertContact(String name, String image) {
SQLiteDatabase db = getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(CATEGORY_NAME, name);
contentValues.put(CATEGORY_IMAGE, image);
db.insert(CATEGORY_TABLE_NAME, null, contentValues);
db.close();
return true;
}
public Cursor getData(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery("select * from " + CATEGORY_TABLE_NAME + " where id=" + id + "", null);
db.close();
return res;
}
public int numberOfRows() {
SQLiteDatabase db = this.getReadableDatabase();
int numRows = (int) DatabaseUtils.queryNumEntries(db, CATEGORY_TABLE_NAME);
db.close();
return numRows;
}
public boolean updateContact(Integer id, String name, String image) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(CATEGORY_NAME, name);
contentValues.put(CATEGORY_IMAGE, image);
db.update("contacts", contentValues, "id = ? ", new String[]{Integer.toString(id)});
db.close();
return true;
}
public Integer deleteContact(Integer id) {
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(CATEGORY_TABLE_NAME, "id = ? ", new String[]{Integer.toString(id)});
}
public ArrayList<Platform> getAllCotacts() {
ArrayList<Platform> array_list = new ArrayList<Platform>();
String s;
ArrayList<Platform> list;
list = new ArrayList();
//hp = new HashMap();
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery("select * from " + CATEGORY_TABLE_NAME, null);
res.moveToFirst();
while (res.isAfterLast() == false) {
list.add(new Platform(res.getString(res.getColumnIndex(CATEGORY_NAME)), Integer.parseInt(CATEGORY_IMAGE)));
res.moveToNext();
}
db.close();
return array_list;
}
}
This is the class that call to the DBHelper
public class AddNewCategory extends AppCompatActivity implements View.OnClickListener {
private EditText editText;
private ImageView categoryImageView;
DBHelper mydb;
#Override
protected void onCreate(Bundle savedInstanceState) {
mydb = new DBHelper(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.add_new_category);
editText = (EditText) findViewById(R.id.new_category_name);
categoryImageView = (ImageView) findViewById(R.id.new_category_image);
Button button = (Button) findViewById(R.id.send_new_category);
button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
MainActivity.flag = true;
Toast.makeText(this, editText.getText(), Toast.LENGTH_LONG).show();
String images = categoryImageView.getTag().toString();
String names=editText.getText().toString();
mydb.insertContact(names, images);
Toast.makeText(this,"success", Toast.LENGTH_LONG).show();
}
}

Related Links

Why would there be no debug output when testing my Firefox Addon on mobile using cfx?
How to make the latest entry element in a listview visible all the time
Android: Scrolling to slow on gridview?
Android go to device all apps screen
2D rotation openGL es 2.0
Mvvmcross: Interacting with android service
Hide custom windows title util it is completely constructed
Android facebook applicationId cannot be null error despite correct app_id
Number Picker as present in Dialog (Android)
Analytics v2 for android
OutOfMemory when having many images in the screen
Retrieve blob from sqlite
Cannot properly include android support appcompat in my app - or at least, not the themes
Android OpenCV getPerspectiveTransform and warpPerspective
Release version of *.apk in Android Studio
Read raw resource from library project using Context.createPackageContext()

Categories

HOME
android
algorithm
merge
amp-html
jax-rs
grafana
static-site
spring-data-mongodb
nsbundle
gluon-mobile
sendgrid-api-v3
ibeacon-android
watson-conversation
redis-sentinel
xcodebuild
rtf
selenium-ide
flash-player
google-content-api
video-editing
cfml
topology
undertow
named-entity-recognition
roslyn
mount
froala
definitelytyped
moses
custom-post-type
bulletphysics
event-flow
zend-debugger
sql-server-2000
testbed
r-grid
activexobject
modalviewcontroller
pdw-file-browser
slacktextviewcontroller
navigator
parse-tree
bc
diacritics
signals-slots
tasm
azure-arm
skylink
puredata
nanoc
chai-as-promised
scalding
backbone-collections
css-transforms
mouseleave
trigger.io
swingworker
polyline
node-request
async.js
file-uri
nikeplus-api
lua-telegram-bot
cda
realsense
jaunt-api
sapi
linklabel
assertion
gocql
flock
vacuum
linked-tables
pyobjc
snoop
jquery-forms-plugin
dot.js
mmwormhole
bcache
filesplitting
crowd
administration
nsmenu
jquery-slider
gae-quotas
windows-embedded-standard
ie8-compatibility-mode
mbunit
ebay-lms
flex++
composite-component
insert-id
alice
android-loadermanager
pyunit
oracle-enterprise-linux
node-redis
codebase
collectionviewsource
commerceserver2007
eclipse-marketplace
build-environment
alsb

Resources

Encrypt Message