When I am deleting from down to up it's working fine and it gets crashed when my order changes. I have written the delete function in sqlite class. I have tried everything, but it gets crashed when I am randomly delete it.why this question is getting close the question is clear enough to know what is the problem
class Adapter(var context:Context, data: ArrayList<Subject>):RecyclerView.Adapter<Adapter.ViewHolder>()
{
lateinit var db:SQHelper
var data:ArrayList<Subject>
init{
this.data=data
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layout=LayoutInflater.from(context).inflate(R.layout.item_subject,parent,false)
return ViewHolder(layout)
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.title.text=data[position].title
holder.id.text=data[position].id
holder.desc.text=data[position].desc
holder.delete.setOnClickListener {
db = SQHelper(context)
if (db.Delete_data(data[position].id) > 0){
this.data.removeAt(position)
this.notifyItemRemoved(position)
}
}
override fun getItemCount(): Int {
return data.size
}
class ViewHolder(item: View):RecyclerView.ViewHolder(item)
{
internal var title:TextView
internal var id:TextView
internal var desc:TextView
internal var delete:Button
init {
title=item.findViewById(R.id.title_textview)
id=item.findViewById(R.id.id_textview)
desc=item.findViewById(R.id.desc_textview)
delete=item.findViewById(R.id.delete_btn)
}
}
}
//this is adapter
class SQHelper(context:Context):SQLiteOpenHelper(context, DB_name,null,1)
{
companion object{ //place where we can add variables
val DB_name="subjects.db "
val TB_name="Subject "
val id="ID"
val title ="S_title"
val desc="S_desc"
}
override fun onCreate(db: SQLiteDatabase?) {
db?.execSQL("create table $TB_name(ID INTEGER PRIMARY KEY AUTOINCREMENT,S_title TEXT,S_desc TEXT)")//execsql will help to prepare table udsyntax
}
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
db?.execSQL("DROP TABLE IF EXISTS $TB_name")
}
fun ADD_DATA(title_text:String,desc_text:String){
val DB=this.writableDatabase
val values= ContentValues()
values.put(title,title_text)
values.put(desc,desc_text)
DB.insert(TB_name,null,values)
}
fun Delete_data(id:String):Int{
val DB=this.writableDatabase
val item=DB.delete(TB_name,"id=?", arrayOf(id))
return item
}
val data_getter:Cursor get() {
val DB=this.writableDatabase
var data=DB.rawQuery("select * from " + TB_name,null)
return data
}
}
//this is sqlite
//main activity
package com.wordsforfun.myapplication
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
class MainActivity : AppCompatActivity() {
lateinit var miscellaneous: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
miscellaneous=findViewById(R.id.miscellaneous)
miscellaneous.setOnClickListener {
startActivity(Intent(this@MainActivity,option::class.java))
}
}
}
// this is my option class, here in its layout there are two buttons i.e. is add data and saved data .
package com.wordsforfun.myapplication
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
class option : AppCompatActivity() {
lateinit var add_data:Button
lateinit var saved_data:Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_option)
add_data=findViewById(R.id.add_data)
saved_data=findViewById(R.id.saved_data)
add_data.setOnClickListener {
startActivity(Intent(this@option,add_subject::class.java))
}
saved_data.setOnClickListener {
startActivity(Intent(this@option,editmiscellenous::class.java))
}
}
}
//this is my subject class
package com.wordsforfun.myapplication
class Subject (var id:String,var title:String,var desc:String)
// this is my add_subject class, its layout contains two edit text where i can write something to store it in my editmiiscellaneous class
package com.wordsforfun.myapplication
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
class add_subject : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add_subject)
val DB= SQHelper(applicationContext)
val title_input=findViewById<EditText>(R.id.title_edit_text)
val desc_input=findViewById<EditText>(R.id.desc_edit_text)
val add_btn=findViewById<Button>(R.id.add_btn)
add_btn.setOnClickListener{
val title_text=title_input.text.toString().trim()
val desc_text=desc_input.text.toString().trim()
DB.ADD_DATA(title_text,desc_text)
Toast.makeText(this@add_subject,"the subject has been added",Toast.LENGTH_SHORT).show()
startActivity(Intent(this@add_subject, editmiscellenous::class.java))
}
}
}
this is editmiscellaneous class where its layout contains recyclerview and go back button
package com.wordsforfun.myapplication
import android.content.Intent
import android.database.Cursor
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.activity_editmiscellenous.*
class editmiscellenous : AppCompatActivity() {
lateinit var lists: ArrayList<Subject>
lateinit var DB: SQHelper
lateinit var data:Cursor
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_editmiscellenous)
val go =findViewById<Button>(R.id.go)
go.setOnClickListener{
var intent = Intent(this@editmiscellenous,option::class.java)
startActivity(intent)}
lists=ArrayList<Subject>()
DB= SQHelper(applicationContext)
data=DB.data_getter
val adapter=Adapter(applicationContext,lists)
val recycler=findViewById<RecyclerView>(R.id.list)
showData()
list.layoutManager=GridLayoutManager(applicationContext,2)
list.adapter=adapter
}
fun showData()
{
if(data.count==0)
{
Toast.makeText(applicationContext,"There is no item",Toast.LENGTH_SHORT).show()
}
while(data.moveToNext()){
lists.add(Subject(data.getString(0),data.getString(1),data.getString(2)))
}
}
override fun onStart() {
super.onStart()
showData()
}
}
2020-06-25 22:00:35.190 12548-13213/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:00:35.352 12548-12713/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:00:37.096 32548-32600/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:00:37.843 26810-26810/? E/PhoneState: iconId is 0android.widget.ImageView{98df0ba G.ED..... ......I. 0,0-10,28 #7f0a0115 app:id/data_inout}
2020-06-25 22:00:41.014 2914-2914/? E/m.android.phon: Invalid ID 0x00000000.
2020-06-25 22:00:43.003 794-3783/? E/ANDR-PERF-LM: DependentServices: getServices() 89: Service Tracker HAL could not find Client Connections
2020-06-25 22:00:48.802 794-845/? E/ANDR-PERF-RESOURCEQS: Failed to reset optimization [3, 0]
2020-06-25 22:00:54.089 13324-13324/? E/id.defcontaine: Not starting debugger since process cannot load the jdwp agent.
2020-06-25 22:00:54.552 12548-12597/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:00:54.563 12548-12597/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:00:54.603 12548-12713/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:00:54.702 1497-1769/? E/ColorRemovableAppManager: package com.google.android.youtube not in ColorRemovableAppManager
2020-06-25 22:00:56.965 23262-23264/? E/rutils: releaseProcess gCount = 1
2020-06-25 22:01:02.128 1142-2665/? E/installd: Failed to delete /data/app/vmdl781187268.tmp: No such file or directory
2020-06-25 22:01:02.262 1497-1651/? E/system_server: No package ID 7f found for ID 0x7f0804b7.
2020-06-25 22:01:02.263 1497-1651/? E/system_server: No package ID 7f found for ID 0x7f13087d.
2020-06-25 22:01:02.274 13349-13349/? E/ndroid.keychai: Not starting debugger since process cannot load the jdwp agent.
2020-06-25 22:01:02.287 1497-1651/? E/system_server: No package ID 7f found for ID 0x7f0804b9.
2020-06-25 22:01:02.295 1497-1651/? E/system_server: No package ID 7f found for ID 0x7f13090e.
2020-06-25 22:01:02.295 1497-1651/? E/system_server: No package ID 7f found for ID 0x7f0804b5.
2020-06-25 22:01:02.296 1497-1651/? E/system_server: No package ID 7f found for ID 0x7f130341.
2020-06-25 22:01:02.393 13366-13366/? E/os.phonemanage: Not starting debugger since process cannot load the jdwp agent.
2020-06-25 22:01:02.418 8676-8697/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.428 8676-8697/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.482 8676-8697/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.482 8676-8697/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.489 8676-8703/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.502 8676-8697/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.517 8676-8703/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.554 8676-8703/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.596 13385-13385/? E/s.childrenspac: Not starting debugger since process cannot load the jdwp agent.
2020-06-25 22:01:02.630 13406-13406/? E/.android.gms.u: Not starting debugger since process cannot load the jdwp agent.
2020-06-25 22:01:02.671 3957-4647/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.830 13433-13433/? E/os.oppomultiap: Not starting debugger since process cannot load the jdwp agent.
2020-06-25 22:01:02.849 3957-4647/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.852 1497-4241/? E/OppoPackageManager: parserFilterAppList() xml empty, return.
2020-06-25 22:01:02.898 3301-5454/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.902 3301-5454/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.916 3301-5454/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.935 3957-13432/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.951 3957-13432/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.952 3301-5454/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.960 3957-13432/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.970 3957-13432/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:02.973 1497-4594/? E/OppoPackageManager: parserFilterAppList() xml empty, return.
2020-06-25 22:01:02.991 3957-13432/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.000 3301-5454/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.001 3957-13432/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.009 3957-13443/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.015 3301-5454/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.018 3957-13432/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.041 3957-13432/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.045 3957-13443/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.088 2914-2914/? E/PhoneInterfaceManager: [PhoneIntfMgr] getCarrierPackageNamesForIntent: No UICC
2020-06-25 22:01:03.093 3957-4647/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.101 2914-2914/? E/PhoneInterfaceManager: [PhoneIntfMgr] getCarrierPackageNamesForIntent: No UICC
2020-06-25 22:01:03.106 3957-13443/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.113 3957-13443/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.123 3957-13443/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.140 3301-29038/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.140 3957-13443/? E/Parcel: Reading a NULL string not supported here.
2020-06-25 22:01:03.142 13461-13461/? E/.quicksearchbo: Not starting debugger since process cannot load the jdwp agent.
obj=AppBindData{appInfo=ApplicationInfo{6c44f3 com.google.android.gms}} } , cost = 1577 ms
2020-06-25 22:01:04.279 13406-13406/? E/ANR_LOG: >>>Current msg List is:
2020-06-25 22:01:04.279 13406-13406/? E/ANR_LOG: Current msg <1> = { when=-1s582ms what=114 target=android.app.ActivityThread$H obj=CreateServiceData{token=android.os.BinderProxy@20d95b0 className=com.google.android.gms.chimera.UiIntentOperationService packageName=com.google.android.gms intent=null} }
2020-06-25 22:01:04.279 13406-13406/? E/ANR_LOG: Current msg <2> = { when=-1s573ms what=115 target=android.app.ActivityThread$H obj=ServiceArgsData{token=android.os.BinderProxy@20d95b0 startId=1 args=Intent { act=com.google.android.gms.autofill.sharedpreferences.SLAVE cat=[targeted_intent_op_prefix:.autofill.sharedpreferences.RemoteIntentOperation] cmp=com.google.android.gms/.chimera.UiIntentOperationService (has extras) }} }
at com.oppo.gallery3d.provider.AlbumsProvider.a(AlbumsProvider.java:377)
at com.oppo.gallery3d.provider.AlbumsProvider.bulkInsert(AlbumsProvider.java:164)
at android.content.ContentProvider$Transport.bulkInsert(ContentProvider.java:286)
at android.content.ContentResolver.bulkInsert(ContentResolver.java:1741)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:484)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:212)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:179)
at com.oppo.gallery3d.f.ek.q(WhiteList.java:591)
at com.oppo.gallery3d.f.ek.<init>(WhiteList.java:128)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:141)
at com.oppo.gallery3d.search.i.b(SearchDBHelper.java:188)
at com.oppo.gallery3d.search.c.e(GeoCacheService.java:143)
at com.oppo.gallery3d.search.SearchInfoUpdateService$a.a(SearchInfoUpdateService.java:142)
at com.oppo.gallery3d.search.SearchInfoUpdateService$b.run(SearchInfoUpdateService.java:114)
at com.oppo.gallery3d.search.SearchInfoUpdateService$1.handleMessage(SearchInfoUpdateService.java:63)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:226)
at android.os.HandlerThread.run(HandlerThread.java:65)
2020-06-25 22:01:24.416 13853-13882/? E/SQLiteLog: (1) table whitelist_dirs has no column named set_order
2020-06-25 22:01:24.417 13853-13882/? E/SQLiteDatabase: Error inserting bucket_id=-260641417 is_force=1 data=/storage/emulated/999/Tencent/QQ_Video set_order=-1 media_type=3 album_type=0 fix_show=0
android.database.sqlite.SQLiteException: table whitelist_dirs has no column named set_order (code 1 SQLITE_ERROR): , while compiling: INSERT INTO whitelist_dirs(bucket_id,is_force,data,set_order,media_type,album_type,fix_show) VALUES (?,?,?,?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:939)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:550)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1569)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1440)
at com.oppo.gallery3d.provider.AlbumsProvider.a(AlbumsProvider.java:413)
at com.oppo.gallery3d.provider.AlbumsProvider.a(AlbumsProvider.java:377)
at com.oppo.gallery3d.provider.AlbumsProvider.bulkInsert(AlbumsProvider.java:164)
at android.content.ContentProvider$Transport.bulkInsert(ContentProvider.java:286)
at android.content.ContentResolver.bulkInsert(ContentResolver.java:1741)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:484)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:212)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:179)
at com.oppo.gallery3d.f.ek.q(WhiteList.java:591)
at com.oppo.gallery3d.f.ek.<init>(WhiteList.java:128)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:141)
at com.oppo.gallery3d.search.i.b(SearchDBHelper.java:188)
at com.oppo.gallery3d.search.c.e(GeoCacheService.java:143)
at com.oppo.gallery3d.search.SearchInfoUpdateService$a.a(SearchInfoUpdateService.java:142)
at com.oppo.gallery3d.search.SearchInfoUpdateService$b.run(SearchInfoUpdateService.java:114)
at com.oppo.gallery3d.search.SearchInfoUpdateService$1.handleMessage(SearchInfoUpdateService.java:63)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:226)
at android.os.HandlerThread.run(HandlerThread.java:65)
2020-06-25 22:01:24.417 13853-13882/? E/SQLiteLog: (1) table whitelist_dirs has no column named set_order
2020-06-25 22:01:24.418 13853-13882/? E/SQLiteDatabase: Error inserting bucket_id=-1809287853 is_force=1 data=/storage/emulated/999/相机 set_order=-1 media_type=3 album_type=0 fix_show=0
android.database.sqlite.SQLiteException: table whitelist_dirs has no column named set_order (code 1 SQLITE_ERROR): , while compiling: INSERT INTO whitelist_dirs(bucket_id,is_force,data,set_order,media_type,album_type,fix_show) VALUES (?,?,?,?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:939)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:550)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1569)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1440)
at com.oppo.gallery3d.provider.AlbumsProvider.a(AlbumsProvider.java:413)
at com.oppo.gallery3d.provider.AlbumsProvider.a(AlbumsProvider.java:377)
at com.oppo.gallery3d.provider.AlbumsProvider.bulkInsert(AlbumsProvider.java:164)
at android.content.ContentProvider$Transport.bulkInsert(ContentProvider.java:286)
at android.content.ContentResolver.bulkInsert(ContentResolver.java:1741)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:484)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:212)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:179)
at com.oppo.gallery3d.f.ek.q(WhiteList.java:591)
at com.oppo.gallery3d.f.ek.<init>(WhiteList.java:128)
at com.oppo.gallery3d.f.ek.a(WhiteList.java:141)
at com.oppo.gallery3d.search.i.b(SearchDBHelper.java:188)
at com.oppo.gallery3d.search.c.e(GeoCacheService.java:143)
at com.oppo.gallery3d.search.SearchInfoUpdateService$a.a(SearchInfoUpdateService.java:142)
at com.oppo.gallery3d.search.SearchInfoUpdateService$b.run(SearchInfoUpdateService.java:114)
at com.oppo.gallery3d.search.SearchInfoUpdateService$1.handleMessage(SearchInfoUpdateService.java:63)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:226)
at android.os.HandlerThread.run(HandlerThread.java:65)
2020-06-25 22:01:24.419 13853-13882/? E/SQLiteLog: (1) table whitelist_dirs has no column named set_order
2020-06-25 22:01:24.420 13853-13882/? E/SQLiteDatabase: Error inserting bucket_id=478860548 is_force=1 data=/storage/emulated/999/qqmusic/mv set_order=-1 media_type=3 album_type=0 fix_show=0
android.database.sqlite.SQLiteException: table whitelist_dirs has no column named set_order (code 1 SQLITE_ERROR): , while compiling: INSERT INTO whitelist_dirs(bucket_id,is_force,data,set_order,media_type,album_type,fix_show) VALUES (?,?,?,?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:939)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:550)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1569)
read: unexpected EOF!
User contributions licensed under CC BY-SA 3.0