android-studio 's program crashes while trying to run it
hey everybody i'm french so please excuse my bad english .
i'm a programmer who's learning kotlin and i'm making my first program with android studio so i want to make a button(add) who when pressed will add the content of two textboxes(imp1/imp2) and write it as a result in a third textbox(result) like a calculator but when i press the button it crashes and close the app
add.setOnClickListener{
result.text = (imp1.text as Int + imp2.text as Int) as CharSequence
}
add a comment |
hey everybody i'm french so please excuse my bad english .
i'm a programmer who's learning kotlin and i'm making my first program with android studio so i want to make a button(add) who when pressed will add the content of two textboxes(imp1/imp2) and write it as a result in a third textbox(result) like a calculator but when i press the button it crashes and close the app
add.setOnClickListener{
result.text = (imp1.text as Int + imp2.text as Int) as CharSequence
}
2
Use(imp1.text.toInt() + imp2.text.toInt()).toString()
– EpicPandaForce
Nov 25 '18 at 0:17
thanks for your reply but it says unresolved reference for the 'toInt'
– Med ali Damergi ReTr0
Nov 25 '18 at 7:17
add a comment |
hey everybody i'm french so please excuse my bad english .
i'm a programmer who's learning kotlin and i'm making my first program with android studio so i want to make a button(add) who when pressed will add the content of two textboxes(imp1/imp2) and write it as a result in a third textbox(result) like a calculator but when i press the button it crashes and close the app
add.setOnClickListener{
result.text = (imp1.text as Int + imp2.text as Int) as CharSequence
}
hey everybody i'm french so please excuse my bad english .
i'm a programmer who's learning kotlin and i'm making my first program with android studio so i want to make a button(add) who when pressed will add the content of two textboxes(imp1/imp2) and write it as a result in a third textbox(result) like a calculator but when i press the button it crashes and close the app
add.setOnClickListener{
result.text = (imp1.text as Int + imp2.text as Int) as CharSequence
}
asked Nov 24 '18 at 23:22
Med ali Damergi ReTr0Med ali Damergi ReTr0
31
31
2
Use(imp1.text.toInt() + imp2.text.toInt()).toString()
– EpicPandaForce
Nov 25 '18 at 0:17
thanks for your reply but it says unresolved reference for the 'toInt'
– Med ali Damergi ReTr0
Nov 25 '18 at 7:17
add a comment |
2
Use(imp1.text.toInt() + imp2.text.toInt()).toString()
– EpicPandaForce
Nov 25 '18 at 0:17
thanks for your reply but it says unresolved reference for the 'toInt'
– Med ali Damergi ReTr0
Nov 25 '18 at 7:17
2
2
Use
(imp1.text.toInt() + imp2.text.toInt()).toString()– EpicPandaForce
Nov 25 '18 at 0:17
Use
(imp1.text.toInt() + imp2.text.toInt()).toString()– EpicPandaForce
Nov 25 '18 at 0:17
thanks for your reply but it says unresolved reference for the 'toInt'
– Med ali Damergi ReTr0
Nov 25 '18 at 7:17
thanks for your reply but it says unresolved reference for the 'toInt'
– Med ali Damergi ReTr0
Nov 25 '18 at 7:17
add a comment |
2 Answers
2
active
oldest
votes
I guess imp1 and imp2 are EditTexts,
so imp1.text and imp2.text are of type Editable and not String.
If result is a TextView you must do this:
result.text = (imp1.text.toString().toInt() + imp2.text.toString().toInt()).toString()
or if result is an EditText:
result.setText((imp1.text.toString().toInt() + imp2.text.toString().toInt()).toString())
thank's @forpas it works <3 <3 <3 it's the first time that i ask something in a forum and i never thought it was so helpful
– Med ali Damergi ReTr0
Nov 25 '18 at 13:25
yeah sure sorry i'm kinda newbie on this platform
– Med ali Damergi ReTr0
Nov 25 '18 at 14:05
add a comment |
You can still use old java method
(Integer.parseInt(imp1.text.toString()) + Integer.parseInt(imp2.text.toString()))
yeah i tried but still not working here's the logs
– Med ali Damergi ReTr0
Nov 25 '18 at 7:56
E/AndroidRuntime: FATAL EXCEPTION: main
– Med ali Damergi ReTr0
Nov 25 '18 at 7:57
Process: com.example.dalid.myapplication, PID: 11447 android.content.res.Resources$NotFoundException: String resource ID #0x9 at android.content.res.Resources.getText(Resources.java:410) at android.content.res.HwResources.getText(HwResources.java:465) at android.widget.TextView.setText(TextView.java:5589) at com.example.dalid.myapplication.MainActivity$onCreate$1.onClick(MainActivity.kt:16) at android.view.View.performClick(View.java:6291) at android.view.View$PerformClick.run(View.java:24931)
– Med ali Damergi ReTr0
Nov 25 '18 at 8:00
` at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7425) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)` it may help
– Med ali Damergi ReTr0
Nov 25 '18 at 8:01
add a 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%2f53463251%2fandroid-studio-s-program-crashes-while-trying-to-run-it%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
I guess imp1 and imp2 are EditTexts,
so imp1.text and imp2.text are of type Editable and not String.
If result is a TextView you must do this:
result.text = (imp1.text.toString().toInt() + imp2.text.toString().toInt()).toString()
or if result is an EditText:
result.setText((imp1.text.toString().toInt() + imp2.text.toString().toInt()).toString())
thank's @forpas it works <3 <3 <3 it's the first time that i ask something in a forum and i never thought it was so helpful
– Med ali Damergi ReTr0
Nov 25 '18 at 13:25
yeah sure sorry i'm kinda newbie on this platform
– Med ali Damergi ReTr0
Nov 25 '18 at 14:05
add a comment |
I guess imp1 and imp2 are EditTexts,
so imp1.text and imp2.text are of type Editable and not String.
If result is a TextView you must do this:
result.text = (imp1.text.toString().toInt() + imp2.text.toString().toInt()).toString()
or if result is an EditText:
result.setText((imp1.text.toString().toInt() + imp2.text.toString().toInt()).toString())
thank's @forpas it works <3 <3 <3 it's the first time that i ask something in a forum and i never thought it was so helpful
– Med ali Damergi ReTr0
Nov 25 '18 at 13:25
yeah sure sorry i'm kinda newbie on this platform
– Med ali Damergi ReTr0
Nov 25 '18 at 14:05
add a comment |
I guess imp1 and imp2 are EditTexts,
so imp1.text and imp2.text are of type Editable and not String.
If result is a TextView you must do this:
result.text = (imp1.text.toString().toInt() + imp2.text.toString().toInt()).toString()
or if result is an EditText:
result.setText((imp1.text.toString().toInt() + imp2.text.toString().toInt()).toString())
I guess imp1 and imp2 are EditTexts,
so imp1.text and imp2.text are of type Editable and not String.
If result is a TextView you must do this:
result.text = (imp1.text.toString().toInt() + imp2.text.toString().toInt()).toString()
or if result is an EditText:
result.setText((imp1.text.toString().toInt() + imp2.text.toString().toInt()).toString())
answered Nov 25 '18 at 9:56
forpasforpas
15.7k3626
15.7k3626
thank's @forpas it works <3 <3 <3 it's the first time that i ask something in a forum and i never thought it was so helpful
– Med ali Damergi ReTr0
Nov 25 '18 at 13:25
yeah sure sorry i'm kinda newbie on this platform
– Med ali Damergi ReTr0
Nov 25 '18 at 14:05
add a comment |
thank's @forpas it works <3 <3 <3 it's the first time that i ask something in a forum and i never thought it was so helpful
– Med ali Damergi ReTr0
Nov 25 '18 at 13:25
yeah sure sorry i'm kinda newbie on this platform
– Med ali Damergi ReTr0
Nov 25 '18 at 14:05
thank's @forpas it works <3 <3 <3 it's the first time that i ask something in a forum and i never thought it was so helpful
– Med ali Damergi ReTr0
Nov 25 '18 at 13:25
thank's @forpas it works <3 <3 <3 it's the first time that i ask something in a forum and i never thought it was so helpful
– Med ali Damergi ReTr0
Nov 25 '18 at 13:25
yeah sure sorry i'm kinda newbie on this platform
– Med ali Damergi ReTr0
Nov 25 '18 at 14:05
yeah sure sorry i'm kinda newbie on this platform
– Med ali Damergi ReTr0
Nov 25 '18 at 14:05
add a comment |
You can still use old java method
(Integer.parseInt(imp1.text.toString()) + Integer.parseInt(imp2.text.toString()))
yeah i tried but still not working here's the logs
– Med ali Damergi ReTr0
Nov 25 '18 at 7:56
E/AndroidRuntime: FATAL EXCEPTION: main
– Med ali Damergi ReTr0
Nov 25 '18 at 7:57
Process: com.example.dalid.myapplication, PID: 11447 android.content.res.Resources$NotFoundException: String resource ID #0x9 at android.content.res.Resources.getText(Resources.java:410) at android.content.res.HwResources.getText(HwResources.java:465) at android.widget.TextView.setText(TextView.java:5589) at com.example.dalid.myapplication.MainActivity$onCreate$1.onClick(MainActivity.kt:16) at android.view.View.performClick(View.java:6291) at android.view.View$PerformClick.run(View.java:24931)
– Med ali Damergi ReTr0
Nov 25 '18 at 8:00
` at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7425) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)` it may help
– Med ali Damergi ReTr0
Nov 25 '18 at 8:01
add a comment |
You can still use old java method
(Integer.parseInt(imp1.text.toString()) + Integer.parseInt(imp2.text.toString()))
yeah i tried but still not working here's the logs
– Med ali Damergi ReTr0
Nov 25 '18 at 7:56
E/AndroidRuntime: FATAL EXCEPTION: main
– Med ali Damergi ReTr0
Nov 25 '18 at 7:57
Process: com.example.dalid.myapplication, PID: 11447 android.content.res.Resources$NotFoundException: String resource ID #0x9 at android.content.res.Resources.getText(Resources.java:410) at android.content.res.HwResources.getText(HwResources.java:465) at android.widget.TextView.setText(TextView.java:5589) at com.example.dalid.myapplication.MainActivity$onCreate$1.onClick(MainActivity.kt:16) at android.view.View.performClick(View.java:6291) at android.view.View$PerformClick.run(View.java:24931)
– Med ali Damergi ReTr0
Nov 25 '18 at 8:00
` at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7425) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)` it may help
– Med ali Damergi ReTr0
Nov 25 '18 at 8:01
add a comment |
You can still use old java method
(Integer.parseInt(imp1.text.toString()) + Integer.parseInt(imp2.text.toString()))
You can still use old java method
(Integer.parseInt(imp1.text.toString()) + Integer.parseInt(imp2.text.toString()))
answered Nov 25 '18 at 7:09
Jawad AhmedJawad Ahmed
776
776
yeah i tried but still not working here's the logs
– Med ali Damergi ReTr0
Nov 25 '18 at 7:56
E/AndroidRuntime: FATAL EXCEPTION: main
– Med ali Damergi ReTr0
Nov 25 '18 at 7:57
Process: com.example.dalid.myapplication, PID: 11447 android.content.res.Resources$NotFoundException: String resource ID #0x9 at android.content.res.Resources.getText(Resources.java:410) at android.content.res.HwResources.getText(HwResources.java:465) at android.widget.TextView.setText(TextView.java:5589) at com.example.dalid.myapplication.MainActivity$onCreate$1.onClick(MainActivity.kt:16) at android.view.View.performClick(View.java:6291) at android.view.View$PerformClick.run(View.java:24931)
– Med ali Damergi ReTr0
Nov 25 '18 at 8:00
` at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7425) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)` it may help
– Med ali Damergi ReTr0
Nov 25 '18 at 8:01
add a comment |
yeah i tried but still not working here's the logs
– Med ali Damergi ReTr0
Nov 25 '18 at 7:56
E/AndroidRuntime: FATAL EXCEPTION: main
– Med ali Damergi ReTr0
Nov 25 '18 at 7:57
Process: com.example.dalid.myapplication, PID: 11447 android.content.res.Resources$NotFoundException: String resource ID #0x9 at android.content.res.Resources.getText(Resources.java:410) at android.content.res.HwResources.getText(HwResources.java:465) at android.widget.TextView.setText(TextView.java:5589) at com.example.dalid.myapplication.MainActivity$onCreate$1.onClick(MainActivity.kt:16) at android.view.View.performClick(View.java:6291) at android.view.View$PerformClick.run(View.java:24931)
– Med ali Damergi ReTr0
Nov 25 '18 at 8:00
` at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7425) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)` it may help
– Med ali Damergi ReTr0
Nov 25 '18 at 8:01
yeah i tried but still not working here's the logs
– Med ali Damergi ReTr0
Nov 25 '18 at 7:56
yeah i tried but still not working here's the logs
– Med ali Damergi ReTr0
Nov 25 '18 at 7:56
E/AndroidRuntime: FATAL EXCEPTION: main
– Med ali Damergi ReTr0
Nov 25 '18 at 7:57
E/AndroidRuntime: FATAL EXCEPTION: main
– Med ali Damergi ReTr0
Nov 25 '18 at 7:57
Process: com.example.dalid.myapplication, PID: 11447 android.content.res.Resources$NotFoundException: String resource ID #0x9 at android.content.res.Resources.getText(Resources.java:410) at android.content.res.HwResources.getText(HwResources.java:465) at android.widget.TextView.setText(TextView.java:5589) at com.example.dalid.myapplication.MainActivity$onCreate$1.onClick(MainActivity.kt:16) at android.view.View.performClick(View.java:6291) at android.view.View$PerformClick.run(View.java:24931)– Med ali Damergi ReTr0
Nov 25 '18 at 8:00
Process: com.example.dalid.myapplication, PID: 11447 android.content.res.Resources$NotFoundException: String resource ID #0x9 at android.content.res.Resources.getText(Resources.java:410) at android.content.res.HwResources.getText(HwResources.java:465) at android.widget.TextView.setText(TextView.java:5589) at com.example.dalid.myapplication.MainActivity$onCreate$1.onClick(MainActivity.kt:16) at android.view.View.performClick(View.java:6291) at android.view.View$PerformClick.run(View.java:24931)– Med ali Damergi ReTr0
Nov 25 '18 at 8:00
` at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7425) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)` it may help
– Med ali Damergi ReTr0
Nov 25 '18 at 8:01
` at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7425) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)` it may help
– Med ali Damergi ReTr0
Nov 25 '18 at 8:01
add a 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%2f53463251%2fandroid-studio-s-program-crashes-while-trying-to-run-it%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
2
Use
(imp1.text.toInt() + imp2.text.toInt()).toString()– EpicPandaForce
Nov 25 '18 at 0:17
thanks for your reply but it says unresolved reference for the 'toInt'
– Med ali Damergi ReTr0
Nov 25 '18 at 7:17