Initialize database using kotlin in AsyncTask
In my doInBackground
I declare and Initialize db, I got an error which say type mismatch. What should I put instead of putting this
?
var dbHelper: MyDBHelper? = null
dbHelper = MyDBHelper(this)
What should I put, There say Required: Context!
And this is my async task code, That Problem at dbHelper = MyDBHelper(this)
.
private class UpgradeDB(textView: TextView?) : AsyncTask<String, String, String>() {
var innerTextView: TextView? = textView
override fun onPreExecute() {
innerTextView!!.visibility = View.VISIBLE
}
override fun doInBackground(vararg params: String): String? {
val filename = "eBOSSInv_Upgrade.sql"
val sdcard = Environment.getExternalStorageDirectory()
val file = File(sdcard, filename)
if (!file.exists()) isCancelled
try {
var dbHelper: MyDBHelper? = null
dbHelper = MyDBHelper(this)
dbHelper!!.writableDatabase.use { db ->
var intTotalLine = 0
var intLine = 1
BufferedReader(FileReader(file)).useLines { _ -> intTotalLine++ }
BufferedReader(FileReader(file)).use { r ->
r.lineSequence().forEach {
if (it.isNotEmpty()) {
db!!.execSQL(it)
publishProgress(String.format("Updating %s/%s records", intLine, intTotalLine))
intLine++
}
}
}
}
} catch (e: Exception) {
}
return null
}
override fun onProgressUpdate(vararg text: String) {
innerTextView!!.text = text[0]
}
override fun onPostExecute(result: String?) {
innerTextView!!.text = ""
}
override fun onCancelled() {
}
}
android kotlin
|
show 1 more comment
In my doInBackground
I declare and Initialize db, I got an error which say type mismatch. What should I put instead of putting this
?
var dbHelper: MyDBHelper? = null
dbHelper = MyDBHelper(this)
What should I put, There say Required: Context!
And this is my async task code, That Problem at dbHelper = MyDBHelper(this)
.
private class UpgradeDB(textView: TextView?) : AsyncTask<String, String, String>() {
var innerTextView: TextView? = textView
override fun onPreExecute() {
innerTextView!!.visibility = View.VISIBLE
}
override fun doInBackground(vararg params: String): String? {
val filename = "eBOSSInv_Upgrade.sql"
val sdcard = Environment.getExternalStorageDirectory()
val file = File(sdcard, filename)
if (!file.exists()) isCancelled
try {
var dbHelper: MyDBHelper? = null
dbHelper = MyDBHelper(this)
dbHelper!!.writableDatabase.use { db ->
var intTotalLine = 0
var intLine = 1
BufferedReader(FileReader(file)).useLines { _ -> intTotalLine++ }
BufferedReader(FileReader(file)).use { r ->
r.lineSequence().forEach {
if (it.isNotEmpty()) {
db!!.execSQL(it)
publishProgress(String.format("Updating %s/%s records", intLine, intTotalLine))
intLine++
}
}
}
}
} catch (e: Exception) {
}
return null
}
override fun onProgressUpdate(vararg text: String) {
innerTextView!!.text = text[0]
}
override fun onPostExecute(result: String?) {
innerTextView!!.text = ""
}
override fun onCancelled() {
}
}
android kotlin
"MainActivity@this" like this
– Mustafa Bohra
Nov 26 '18 at 7:11
Please show a Minimal, Complete, and Verifiable example of all relevant code. What isthis
here? Where is the AsyncTask located? Do you really need to declare the database inside the AsyncTask?
– cricket_007
Nov 26 '18 at 7:12
Sorry this may sound a bit blunt, but maybe you should focus on understanding Android before you go about working with Kotlin also, which looks like you haven't worked with much (looking at the code). You have quite a lot of issues in the Android code, that are not specific to Kotlin and if you don't know whatthis
is in this case, then I guess you haven't even written the code in the first place. I think you're digging in too deep into areas that you don't fully understand yet. Depending on whatthis
is here it looks like you could end up with a memory leak for instance.
– Darwind
Nov 26 '18 at 9:16
1
problem fixed. Thank you guys~
– low zaii
Nov 26 '18 at 9:19
Noted, But Those code was done by previous employee, It caused me a lot of problems. @Darwind
– low zaii
Nov 26 '18 at 9:24
|
show 1 more comment
In my doInBackground
I declare and Initialize db, I got an error which say type mismatch. What should I put instead of putting this
?
var dbHelper: MyDBHelper? = null
dbHelper = MyDBHelper(this)
What should I put, There say Required: Context!
And this is my async task code, That Problem at dbHelper = MyDBHelper(this)
.
private class UpgradeDB(textView: TextView?) : AsyncTask<String, String, String>() {
var innerTextView: TextView? = textView
override fun onPreExecute() {
innerTextView!!.visibility = View.VISIBLE
}
override fun doInBackground(vararg params: String): String? {
val filename = "eBOSSInv_Upgrade.sql"
val sdcard = Environment.getExternalStorageDirectory()
val file = File(sdcard, filename)
if (!file.exists()) isCancelled
try {
var dbHelper: MyDBHelper? = null
dbHelper = MyDBHelper(this)
dbHelper!!.writableDatabase.use { db ->
var intTotalLine = 0
var intLine = 1
BufferedReader(FileReader(file)).useLines { _ -> intTotalLine++ }
BufferedReader(FileReader(file)).use { r ->
r.lineSequence().forEach {
if (it.isNotEmpty()) {
db!!.execSQL(it)
publishProgress(String.format("Updating %s/%s records", intLine, intTotalLine))
intLine++
}
}
}
}
} catch (e: Exception) {
}
return null
}
override fun onProgressUpdate(vararg text: String) {
innerTextView!!.text = text[0]
}
override fun onPostExecute(result: String?) {
innerTextView!!.text = ""
}
override fun onCancelled() {
}
}
android kotlin
In my doInBackground
I declare and Initialize db, I got an error which say type mismatch. What should I put instead of putting this
?
var dbHelper: MyDBHelper? = null
dbHelper = MyDBHelper(this)
What should I put, There say Required: Context!
And this is my async task code, That Problem at dbHelper = MyDBHelper(this)
.
private class UpgradeDB(textView: TextView?) : AsyncTask<String, String, String>() {
var innerTextView: TextView? = textView
override fun onPreExecute() {
innerTextView!!.visibility = View.VISIBLE
}
override fun doInBackground(vararg params: String): String? {
val filename = "eBOSSInv_Upgrade.sql"
val sdcard = Environment.getExternalStorageDirectory()
val file = File(sdcard, filename)
if (!file.exists()) isCancelled
try {
var dbHelper: MyDBHelper? = null
dbHelper = MyDBHelper(this)
dbHelper!!.writableDatabase.use { db ->
var intTotalLine = 0
var intLine = 1
BufferedReader(FileReader(file)).useLines { _ -> intTotalLine++ }
BufferedReader(FileReader(file)).use { r ->
r.lineSequence().forEach {
if (it.isNotEmpty()) {
db!!.execSQL(it)
publishProgress(String.format("Updating %s/%s records", intLine, intTotalLine))
intLine++
}
}
}
}
} catch (e: Exception) {
}
return null
}
override fun onProgressUpdate(vararg text: String) {
innerTextView!!.text = text[0]
}
override fun onPostExecute(result: String?) {
innerTextView!!.text = ""
}
override fun onCancelled() {
}
}
android kotlin
android kotlin
edited Nov 26 '18 at 8:23
low zaii
asked Nov 26 '18 at 7:09
low zaiilow zaii
83
83
"MainActivity@this" like this
– Mustafa Bohra
Nov 26 '18 at 7:11
Please show a Minimal, Complete, and Verifiable example of all relevant code. What isthis
here? Where is the AsyncTask located? Do you really need to declare the database inside the AsyncTask?
– cricket_007
Nov 26 '18 at 7:12
Sorry this may sound a bit blunt, but maybe you should focus on understanding Android before you go about working with Kotlin also, which looks like you haven't worked with much (looking at the code). You have quite a lot of issues in the Android code, that are not specific to Kotlin and if you don't know whatthis
is in this case, then I guess you haven't even written the code in the first place. I think you're digging in too deep into areas that you don't fully understand yet. Depending on whatthis
is here it looks like you could end up with a memory leak for instance.
– Darwind
Nov 26 '18 at 9:16
1
problem fixed. Thank you guys~
– low zaii
Nov 26 '18 at 9:19
Noted, But Those code was done by previous employee, It caused me a lot of problems. @Darwind
– low zaii
Nov 26 '18 at 9:24
|
show 1 more comment
"MainActivity@this" like this
– Mustafa Bohra
Nov 26 '18 at 7:11
Please show a Minimal, Complete, and Verifiable example of all relevant code. What isthis
here? Where is the AsyncTask located? Do you really need to declare the database inside the AsyncTask?
– cricket_007
Nov 26 '18 at 7:12
Sorry this may sound a bit blunt, but maybe you should focus on understanding Android before you go about working with Kotlin also, which looks like you haven't worked with much (looking at the code). You have quite a lot of issues in the Android code, that are not specific to Kotlin and if you don't know whatthis
is in this case, then I guess you haven't even written the code in the first place. I think you're digging in too deep into areas that you don't fully understand yet. Depending on whatthis
is here it looks like you could end up with a memory leak for instance.
– Darwind
Nov 26 '18 at 9:16
1
problem fixed. Thank you guys~
– low zaii
Nov 26 '18 at 9:19
Noted, But Those code was done by previous employee, It caused me a lot of problems. @Darwind
– low zaii
Nov 26 '18 at 9:24
"MainActivity@this" like this
– Mustafa Bohra
Nov 26 '18 at 7:11
"MainActivity@this" like this
– Mustafa Bohra
Nov 26 '18 at 7:11
Please show a Minimal, Complete, and Verifiable example of all relevant code. What is
this
here? Where is the AsyncTask located? Do you really need to declare the database inside the AsyncTask?– cricket_007
Nov 26 '18 at 7:12
Please show a Minimal, Complete, and Verifiable example of all relevant code. What is
this
here? Where is the AsyncTask located? Do you really need to declare the database inside the AsyncTask?– cricket_007
Nov 26 '18 at 7:12
Sorry this may sound a bit blunt, but maybe you should focus on understanding Android before you go about working with Kotlin also, which looks like you haven't worked with much (looking at the code). You have quite a lot of issues in the Android code, that are not specific to Kotlin and if you don't know what
this
is in this case, then I guess you haven't even written the code in the first place. I think you're digging in too deep into areas that you don't fully understand yet. Depending on what this
is here it looks like you could end up with a memory leak for instance.– Darwind
Nov 26 '18 at 9:16
Sorry this may sound a bit blunt, but maybe you should focus on understanding Android before you go about working with Kotlin also, which looks like you haven't worked with much (looking at the code). You have quite a lot of issues in the Android code, that are not specific to Kotlin and if you don't know what
this
is in this case, then I guess you haven't even written the code in the first place. I think you're digging in too deep into areas that you don't fully understand yet. Depending on what this
is here it looks like you could end up with a memory leak for instance.– Darwind
Nov 26 '18 at 9:16
1
1
problem fixed. Thank you guys~
– low zaii
Nov 26 '18 at 9:19
problem fixed. Thank you guys~
– low zaii
Nov 26 '18 at 9:19
Noted, But Those code was done by previous employee, It caused me a lot of problems. @Darwind
– low zaii
Nov 26 '18 at 9:24
Noted, But Those code was done by previous employee, It caused me a lot of problems. @Darwind
– low zaii
Nov 26 '18 at 9:24
|
show 1 more comment
2 Answers
2
active
oldest
votes
You need to pass context
into Async Task
.
Example:
llUpdate.setOnClickListener {
UpgradeDB(txtUpdate!!, getApplication()).execute("", "", "")
}
Then in UpgradeDB
, initialize the context.
private class UpgradeDB(textView: TextView?, context: Context) : AsyncTask<String, String, String>() {
var innerTextView: TextView? = textView
var mContext:Context? = context // initialize context
}
And finally
dbHelper = MyDBHelper(mContext)
It works,Thank you very much.
– low zaii
Nov 26 '18 at 9:12
@lowzaii my pleasure
– John Joe
Nov 26 '18 at 9:13
While this will solve the problem I think you should mention that this might cause issues, as you leave aContext
hanging around in anAsyncTask
that potentially doesn't finish before theContext
is gone. What issues might this cause?
– Darwind
Nov 26 '18 at 9:18
add a comment |
It depends where you try to create this object. Unless you do it in a class that extends Context (like Activity) it is not supposed to work. You can try such construct:
There are two ways you gan go:
The simpler way: Declare your AsyncTask as inner class inside tour activity and reference context using label. To declare class as inner you need to place it inside another class and add inner keyowrd:
class A {
inner class B
}
Now you can reference context from inside your async task like that:
dbHelper = DbHelper([ActivityName]@this)
Nevertheless, this is easy way to cause a memory leak, you can read more here: Android AsyncTask memory leaks
The better way is to extract AsyncTask to another class and pass an application context to it, instead of Activity.
I'm using thisdbHelper = MyBDHelper([MainDBAdminActivity]@this)
, It's doesn't work.
– low zaii
Nov 26 '18 at 7:24
@lowzaii could you please show your activity and async task code?
– Michał Powłoka
Nov 26 '18 at 7:52
can you open a chat room ? @Michal Powloka
– low zaii
Nov 26 '18 at 8:03
@lowzaii Not really. You'd do best if you add it to your question, as mentioned in comment. If you cannot share actual code you can just include important parts or write simmilar example.
– Michał Powłoka
Nov 26 '18 at 8:15
Okay, I've updated my code. @Michal Powloka
– low zaii
Nov 26 '18 at 8:24
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476189%2finitialize-database-using-kotlin-in-asynctask%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to pass context
into Async Task
.
Example:
llUpdate.setOnClickListener {
UpgradeDB(txtUpdate!!, getApplication()).execute("", "", "")
}
Then in UpgradeDB
, initialize the context.
private class UpgradeDB(textView: TextView?, context: Context) : AsyncTask<String, String, String>() {
var innerTextView: TextView? = textView
var mContext:Context? = context // initialize context
}
And finally
dbHelper = MyDBHelper(mContext)
It works,Thank you very much.
– low zaii
Nov 26 '18 at 9:12
@lowzaii my pleasure
– John Joe
Nov 26 '18 at 9:13
While this will solve the problem I think you should mention that this might cause issues, as you leave aContext
hanging around in anAsyncTask
that potentially doesn't finish before theContext
is gone. What issues might this cause?
– Darwind
Nov 26 '18 at 9:18
add a comment |
You need to pass context
into Async Task
.
Example:
llUpdate.setOnClickListener {
UpgradeDB(txtUpdate!!, getApplication()).execute("", "", "")
}
Then in UpgradeDB
, initialize the context.
private class UpgradeDB(textView: TextView?, context: Context) : AsyncTask<String, String, String>() {
var innerTextView: TextView? = textView
var mContext:Context? = context // initialize context
}
And finally
dbHelper = MyDBHelper(mContext)
It works,Thank you very much.
– low zaii
Nov 26 '18 at 9:12
@lowzaii my pleasure
– John Joe
Nov 26 '18 at 9:13
While this will solve the problem I think you should mention that this might cause issues, as you leave aContext
hanging around in anAsyncTask
that potentially doesn't finish before theContext
is gone. What issues might this cause?
– Darwind
Nov 26 '18 at 9:18
add a comment |
You need to pass context
into Async Task
.
Example:
llUpdate.setOnClickListener {
UpgradeDB(txtUpdate!!, getApplication()).execute("", "", "")
}
Then in UpgradeDB
, initialize the context.
private class UpgradeDB(textView: TextView?, context: Context) : AsyncTask<String, String, String>() {
var innerTextView: TextView? = textView
var mContext:Context? = context // initialize context
}
And finally
dbHelper = MyDBHelper(mContext)
You need to pass context
into Async Task
.
Example:
llUpdate.setOnClickListener {
UpgradeDB(txtUpdate!!, getApplication()).execute("", "", "")
}
Then in UpgradeDB
, initialize the context.
private class UpgradeDB(textView: TextView?, context: Context) : AsyncTask<String, String, String>() {
var innerTextView: TextView? = textView
var mContext:Context? = context // initialize context
}
And finally
dbHelper = MyDBHelper(mContext)
answered Nov 26 '18 at 9:07
John JoeJohn Joe
4,71822260
4,71822260
It works,Thank you very much.
– low zaii
Nov 26 '18 at 9:12
@lowzaii my pleasure
– John Joe
Nov 26 '18 at 9:13
While this will solve the problem I think you should mention that this might cause issues, as you leave aContext
hanging around in anAsyncTask
that potentially doesn't finish before theContext
is gone. What issues might this cause?
– Darwind
Nov 26 '18 at 9:18
add a comment |
It works,Thank you very much.
– low zaii
Nov 26 '18 at 9:12
@lowzaii my pleasure
– John Joe
Nov 26 '18 at 9:13
While this will solve the problem I think you should mention that this might cause issues, as you leave aContext
hanging around in anAsyncTask
that potentially doesn't finish before theContext
is gone. What issues might this cause?
– Darwind
Nov 26 '18 at 9:18
It works,Thank you very much.
– low zaii
Nov 26 '18 at 9:12
It works,Thank you very much.
– low zaii
Nov 26 '18 at 9:12
@lowzaii my pleasure
– John Joe
Nov 26 '18 at 9:13
@lowzaii my pleasure
– John Joe
Nov 26 '18 at 9:13
While this will solve the problem I think you should mention that this might cause issues, as you leave a
Context
hanging around in an AsyncTask
that potentially doesn't finish before the Context
is gone. What issues might this cause?– Darwind
Nov 26 '18 at 9:18
While this will solve the problem I think you should mention that this might cause issues, as you leave a
Context
hanging around in an AsyncTask
that potentially doesn't finish before the Context
is gone. What issues might this cause?– Darwind
Nov 26 '18 at 9:18
add a comment |
It depends where you try to create this object. Unless you do it in a class that extends Context (like Activity) it is not supposed to work. You can try such construct:
There are two ways you gan go:
The simpler way: Declare your AsyncTask as inner class inside tour activity and reference context using label. To declare class as inner you need to place it inside another class and add inner keyowrd:
class A {
inner class B
}
Now you can reference context from inside your async task like that:
dbHelper = DbHelper([ActivityName]@this)
Nevertheless, this is easy way to cause a memory leak, you can read more here: Android AsyncTask memory leaks
The better way is to extract AsyncTask to another class and pass an application context to it, instead of Activity.
I'm using thisdbHelper = MyBDHelper([MainDBAdminActivity]@this)
, It's doesn't work.
– low zaii
Nov 26 '18 at 7:24
@lowzaii could you please show your activity and async task code?
– Michał Powłoka
Nov 26 '18 at 7:52
can you open a chat room ? @Michal Powloka
– low zaii
Nov 26 '18 at 8:03
@lowzaii Not really. You'd do best if you add it to your question, as mentioned in comment. If you cannot share actual code you can just include important parts or write simmilar example.
– Michał Powłoka
Nov 26 '18 at 8:15
Okay, I've updated my code. @Michal Powloka
– low zaii
Nov 26 '18 at 8:24
|
show 1 more comment
It depends where you try to create this object. Unless you do it in a class that extends Context (like Activity) it is not supposed to work. You can try such construct:
There are two ways you gan go:
The simpler way: Declare your AsyncTask as inner class inside tour activity and reference context using label. To declare class as inner you need to place it inside another class and add inner keyowrd:
class A {
inner class B
}
Now you can reference context from inside your async task like that:
dbHelper = DbHelper([ActivityName]@this)
Nevertheless, this is easy way to cause a memory leak, you can read more here: Android AsyncTask memory leaks
The better way is to extract AsyncTask to another class and pass an application context to it, instead of Activity.
I'm using thisdbHelper = MyBDHelper([MainDBAdminActivity]@this)
, It's doesn't work.
– low zaii
Nov 26 '18 at 7:24
@lowzaii could you please show your activity and async task code?
– Michał Powłoka
Nov 26 '18 at 7:52
can you open a chat room ? @Michal Powloka
– low zaii
Nov 26 '18 at 8:03
@lowzaii Not really. You'd do best if you add it to your question, as mentioned in comment. If you cannot share actual code you can just include important parts or write simmilar example.
– Michał Powłoka
Nov 26 '18 at 8:15
Okay, I've updated my code. @Michal Powloka
– low zaii
Nov 26 '18 at 8:24
|
show 1 more comment
It depends where you try to create this object. Unless you do it in a class that extends Context (like Activity) it is not supposed to work. You can try such construct:
There are two ways you gan go:
The simpler way: Declare your AsyncTask as inner class inside tour activity and reference context using label. To declare class as inner you need to place it inside another class and add inner keyowrd:
class A {
inner class B
}
Now you can reference context from inside your async task like that:
dbHelper = DbHelper([ActivityName]@this)
Nevertheless, this is easy way to cause a memory leak, you can read more here: Android AsyncTask memory leaks
The better way is to extract AsyncTask to another class and pass an application context to it, instead of Activity.
It depends where you try to create this object. Unless you do it in a class that extends Context (like Activity) it is not supposed to work. You can try such construct:
There are two ways you gan go:
The simpler way: Declare your AsyncTask as inner class inside tour activity and reference context using label. To declare class as inner you need to place it inside another class and add inner keyowrd:
class A {
inner class B
}
Now you can reference context from inside your async task like that:
dbHelper = DbHelper([ActivityName]@this)
Nevertheless, this is easy way to cause a memory leak, you can read more here: Android AsyncTask memory leaks
The better way is to extract AsyncTask to another class and pass an application context to it, instead of Activity.
edited Nov 26 '18 at 7:22
answered Nov 26 '18 at 7:13
Michał PowłokaMichał Powłoka
161113
161113
I'm using thisdbHelper = MyBDHelper([MainDBAdminActivity]@this)
, It's doesn't work.
– low zaii
Nov 26 '18 at 7:24
@lowzaii could you please show your activity and async task code?
– Michał Powłoka
Nov 26 '18 at 7:52
can you open a chat room ? @Michal Powloka
– low zaii
Nov 26 '18 at 8:03
@lowzaii Not really. You'd do best if you add it to your question, as mentioned in comment. If you cannot share actual code you can just include important parts or write simmilar example.
– Michał Powłoka
Nov 26 '18 at 8:15
Okay, I've updated my code. @Michal Powloka
– low zaii
Nov 26 '18 at 8:24
|
show 1 more comment
I'm using thisdbHelper = MyBDHelper([MainDBAdminActivity]@this)
, It's doesn't work.
– low zaii
Nov 26 '18 at 7:24
@lowzaii could you please show your activity and async task code?
– Michał Powłoka
Nov 26 '18 at 7:52
can you open a chat room ? @Michal Powloka
– low zaii
Nov 26 '18 at 8:03
@lowzaii Not really. You'd do best if you add it to your question, as mentioned in comment. If you cannot share actual code you can just include important parts or write simmilar example.
– Michał Powłoka
Nov 26 '18 at 8:15
Okay, I've updated my code. @Michal Powloka
– low zaii
Nov 26 '18 at 8:24
I'm using this
dbHelper = MyBDHelper([MainDBAdminActivity]@this)
, It's doesn't work.– low zaii
Nov 26 '18 at 7:24
I'm using this
dbHelper = MyBDHelper([MainDBAdminActivity]@this)
, It's doesn't work.– low zaii
Nov 26 '18 at 7:24
@lowzaii could you please show your activity and async task code?
– Michał Powłoka
Nov 26 '18 at 7:52
@lowzaii could you please show your activity and async task code?
– Michał Powłoka
Nov 26 '18 at 7:52
can you open a chat room ? @Michal Powloka
– low zaii
Nov 26 '18 at 8:03
can you open a chat room ? @Michal Powloka
– low zaii
Nov 26 '18 at 8:03
@lowzaii Not really. You'd do best if you add it to your question, as mentioned in comment. If you cannot share actual code you can just include important parts or write simmilar example.
– Michał Powłoka
Nov 26 '18 at 8:15
@lowzaii Not really. You'd do best if you add it to your question, as mentioned in comment. If you cannot share actual code you can just include important parts or write simmilar example.
– Michał Powłoka
Nov 26 '18 at 8:15
Okay, I've updated my code. @Michal Powloka
– low zaii
Nov 26 '18 at 8:24
Okay, I've updated my code. @Michal Powloka
– low zaii
Nov 26 '18 at 8:24
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476189%2finitialize-database-using-kotlin-in-asynctask%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"MainActivity@this" like this
– Mustafa Bohra
Nov 26 '18 at 7:11
Please show a Minimal, Complete, and Verifiable example of all relevant code. What is
this
here? Where is the AsyncTask located? Do you really need to declare the database inside the AsyncTask?– cricket_007
Nov 26 '18 at 7:12
Sorry this may sound a bit blunt, but maybe you should focus on understanding Android before you go about working with Kotlin also, which looks like you haven't worked with much (looking at the code). You have quite a lot of issues in the Android code, that are not specific to Kotlin and if you don't know what
this
is in this case, then I guess you haven't even written the code in the first place. I think you're digging in too deep into areas that you don't fully understand yet. Depending on whatthis
is here it looks like you could end up with a memory leak for instance.– Darwind
Nov 26 '18 at 9:16
1
problem fixed. Thank you guys~
– low zaii
Nov 26 '18 at 9:19
Noted, But Those code was done by previous employee, It caused me a lot of problems. @Darwind
– low zaii
Nov 26 '18 at 9:24