Kotlin on Android alters library variable instead of defining a new variable
today I started a new Android project with Kotlin support. But as soon as I launch it on my phone, it is disconnected from Wi-Fi (Application has INTERNET and ACCESS_NETWORK_STATE permissons but no socket code yet). Here is the code:
package org.arch.cast
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
class MainActivity : AppCompatActivity()
internal var dummy = 10
internal var channel = 20
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
After experimenting a bit I noticed that one of my variables wasn't marked as "not used" even though it was not used.
This is the only class the project contains right now, no other service or activity exists so nothing is referring channel variable anywhere in the project. I also added a dummy variable to show that it is marked as not used. I noticed that the problem was its name and it was actually not defining it but altering another variable from a library I didn't import. And since it was related to Wi-Fi, phone was disconnecting.
Sure everything works when I change the variable name but this should not be the solution, it is only a temporary workaround. So the question is, how can I prevent Kotlin from altering the variable and make it actually define it in my class?
android android-studio kotlin
|
show 6 more comments
today I started a new Android project with Kotlin support. But as soon as I launch it on my phone, it is disconnected from Wi-Fi (Application has INTERNET and ACCESS_NETWORK_STATE permissons but no socket code yet). Here is the code:
package org.arch.cast
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
class MainActivity : AppCompatActivity()
internal var dummy = 10
internal var channel = 20
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
After experimenting a bit I noticed that one of my variables wasn't marked as "not used" even though it was not used.
This is the only class the project contains right now, no other service or activity exists so nothing is referring channel variable anywhere in the project. I also added a dummy variable to show that it is marked as not used. I noticed that the problem was its name and it was actually not defining it but altering another variable from a library I didn't import. And since it was related to Wi-Fi, phone was disconnecting.
Sure everything works when I change the variable name but this should not be the solution, it is only a temporary workaround. So the question is, how can I prevent Kotlin from altering the variable and make it actually define it in my class?
android android-studio kotlin
Your code does define your own variable, and is not modifying anything. The completion suggestion shows that there is a library type that you can use, but since you're initializing the variable with the value of 10, its type will be Int, and not the Channel type shown in the autocomplete popup. The wifi disconnections are not caused by your code.
– yole
Nov 11 '18 at 21:44
@yole The thing is, simple socket code also works if I change the variable name, but doesn't work if I keep it as "channel" even though I dont use it anywhere. var socket = Socket("10.0.0.10", 1010) on another thread.
– Israphel
Nov 11 '18 at 21:49
Can you post the code as code and not as image please? Makes it easier to try it.
– leonardkraemer
Nov 11 '18 at 21:53
@leonardkraemer sure, i added the code now
– Israphel
Nov 11 '18 at 21:57
1
@Egor setChannel and getChannel was what i meant with "altering" since Kotlin changes obj.setChannel(10) to obj.channel=10. But yes, as i experiment more, it seems coincidential to me too, it started workin when it is named "channel" now. I am asking since i am new to SO, do i mark it as solved now, or simply delete the question since it was a not a valid question?
– Israphel
Nov 11 '18 at 22:13
|
show 6 more comments
today I started a new Android project with Kotlin support. But as soon as I launch it on my phone, it is disconnected from Wi-Fi (Application has INTERNET and ACCESS_NETWORK_STATE permissons but no socket code yet). Here is the code:
package org.arch.cast
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
class MainActivity : AppCompatActivity()
internal var dummy = 10
internal var channel = 20
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
After experimenting a bit I noticed that one of my variables wasn't marked as "not used" even though it was not used.
This is the only class the project contains right now, no other service or activity exists so nothing is referring channel variable anywhere in the project. I also added a dummy variable to show that it is marked as not used. I noticed that the problem was its name and it was actually not defining it but altering another variable from a library I didn't import. And since it was related to Wi-Fi, phone was disconnecting.
Sure everything works when I change the variable name but this should not be the solution, it is only a temporary workaround. So the question is, how can I prevent Kotlin from altering the variable and make it actually define it in my class?
android android-studio kotlin
today I started a new Android project with Kotlin support. But as soon as I launch it on my phone, it is disconnected from Wi-Fi (Application has INTERNET and ACCESS_NETWORK_STATE permissons but no socket code yet). Here is the code:
package org.arch.cast
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
class MainActivity : AppCompatActivity()
internal var dummy = 10
internal var channel = 20
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
After experimenting a bit I noticed that one of my variables wasn't marked as "not used" even though it was not used.
This is the only class the project contains right now, no other service or activity exists so nothing is referring channel variable anywhere in the project. I also added a dummy variable to show that it is marked as not used. I noticed that the problem was its name and it was actually not defining it but altering another variable from a library I didn't import. And since it was related to Wi-Fi, phone was disconnecting.
Sure everything works when I change the variable name but this should not be the solution, it is only a temporary workaround. So the question is, how can I prevent Kotlin from altering the variable and make it actually define it in my class?
android android-studio kotlin
android android-studio kotlin
edited Nov 11 '18 at 22:02
leonardkraemer
3,04811532
3,04811532
asked Nov 11 '18 at 21:40
Israphel
113
113
Your code does define your own variable, and is not modifying anything. The completion suggestion shows that there is a library type that you can use, but since you're initializing the variable with the value of 10, its type will be Int, and not the Channel type shown in the autocomplete popup. The wifi disconnections are not caused by your code.
– yole
Nov 11 '18 at 21:44
@yole The thing is, simple socket code also works if I change the variable name, but doesn't work if I keep it as "channel" even though I dont use it anywhere. var socket = Socket("10.0.0.10", 1010) on another thread.
– Israphel
Nov 11 '18 at 21:49
Can you post the code as code and not as image please? Makes it easier to try it.
– leonardkraemer
Nov 11 '18 at 21:53
@leonardkraemer sure, i added the code now
– Israphel
Nov 11 '18 at 21:57
1
@Egor setChannel and getChannel was what i meant with "altering" since Kotlin changes obj.setChannel(10) to obj.channel=10. But yes, as i experiment more, it seems coincidential to me too, it started workin when it is named "channel" now. I am asking since i am new to SO, do i mark it as solved now, or simply delete the question since it was a not a valid question?
– Israphel
Nov 11 '18 at 22:13
|
show 6 more comments
Your code does define your own variable, and is not modifying anything. The completion suggestion shows that there is a library type that you can use, but since you're initializing the variable with the value of 10, its type will be Int, and not the Channel type shown in the autocomplete popup. The wifi disconnections are not caused by your code.
– yole
Nov 11 '18 at 21:44
@yole The thing is, simple socket code also works if I change the variable name, but doesn't work if I keep it as "channel" even though I dont use it anywhere. var socket = Socket("10.0.0.10", 1010) on another thread.
– Israphel
Nov 11 '18 at 21:49
Can you post the code as code and not as image please? Makes it easier to try it.
– leonardkraemer
Nov 11 '18 at 21:53
@leonardkraemer sure, i added the code now
– Israphel
Nov 11 '18 at 21:57
1
@Egor setChannel and getChannel was what i meant with "altering" since Kotlin changes obj.setChannel(10) to obj.channel=10. But yes, as i experiment more, it seems coincidential to me too, it started workin when it is named "channel" now. I am asking since i am new to SO, do i mark it as solved now, or simply delete the question since it was a not a valid question?
– Israphel
Nov 11 '18 at 22:13
Your code does define your own variable, and is not modifying anything. The completion suggestion shows that there is a library type that you can use, but since you're initializing the variable with the value of 10, its type will be Int, and not the Channel type shown in the autocomplete popup. The wifi disconnections are not caused by your code.
– yole
Nov 11 '18 at 21:44
Your code does define your own variable, and is not modifying anything. The completion suggestion shows that there is a library type that you can use, but since you're initializing the variable with the value of 10, its type will be Int, and not the Channel type shown in the autocomplete popup. The wifi disconnections are not caused by your code.
– yole
Nov 11 '18 at 21:44
@yole The thing is, simple socket code also works if I change the variable name, but doesn't work if I keep it as "channel" even though I dont use it anywhere. var socket = Socket("10.0.0.10", 1010) on another thread.
– Israphel
Nov 11 '18 at 21:49
@yole The thing is, simple socket code also works if I change the variable name, but doesn't work if I keep it as "channel" even though I dont use it anywhere. var socket = Socket("10.0.0.10", 1010) on another thread.
– Israphel
Nov 11 '18 at 21:49
Can you post the code as code and not as image please? Makes it easier to try it.
– leonardkraemer
Nov 11 '18 at 21:53
Can you post the code as code and not as image please? Makes it easier to try it.
– leonardkraemer
Nov 11 '18 at 21:53
@leonardkraemer sure, i added the code now
– Israphel
Nov 11 '18 at 21:57
@leonardkraemer sure, i added the code now
– Israphel
Nov 11 '18 at 21:57
1
1
@Egor setChannel and getChannel was what i meant with "altering" since Kotlin changes obj.setChannel(10) to obj.channel=10. But yes, as i experiment more, it seems coincidential to me too, it started workin when it is named "channel" now. I am asking since i am new to SO, do i mark it as solved now, or simply delete the question since it was a not a valid question?
– Israphel
Nov 11 '18 at 22:13
@Egor setChannel and getChannel was what i meant with "altering" since Kotlin changes obj.setChannel(10) to obj.channel=10. But yes, as i experiment more, it seems coincidential to me too, it started workin when it is named "channel" now. I am asking since i am new to SO, do i mark it as solved now, or simply delete the question since it was a not a valid question?
– Israphel
Nov 11 '18 at 22:13
|
show 6 more comments
0
active
oldest
votes
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%2f53253505%2fkotlin-on-android-alters-library-variable-instead-of-defining-a-new-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53253505%2fkotlin-on-android-alters-library-variable-instead-of-defining-a-new-variable%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
Your code does define your own variable, and is not modifying anything. The completion suggestion shows that there is a library type that you can use, but since you're initializing the variable with the value of 10, its type will be Int, and not the Channel type shown in the autocomplete popup. The wifi disconnections are not caused by your code.
– yole
Nov 11 '18 at 21:44
@yole The thing is, simple socket code also works if I change the variable name, but doesn't work if I keep it as "channel" even though I dont use it anywhere. var socket = Socket("10.0.0.10", 1010) on another thread.
– Israphel
Nov 11 '18 at 21:49
Can you post the code as code and not as image please? Makes it easier to try it.
– leonardkraemer
Nov 11 '18 at 21:53
@leonardkraemer sure, i added the code now
– Israphel
Nov 11 '18 at 21:57
1
@Egor setChannel and getChannel was what i meant with "altering" since Kotlin changes obj.setChannel(10) to obj.channel=10. But yes, as i experiment more, it seems coincidential to me too, it started workin when it is named "channel" now. I am asking since i am new to SO, do i mark it as solved now, or simply delete the question since it was a not a valid question?
– Israphel
Nov 11 '18 at 22:13