Android button not opening other class
I have problems with buttons.I have made 2 buttons that will when pressed open other activity(class).In code there is no error but when I launch emulator it just doesn't work and isn't opening those classes.
My button's btnopis and btnpronadi don't work(they are not opening other activity(class)).But I have button exit that Works and closes app. I don't get where the problem is. Here is the code
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
izlaz();
}
public Button btnopis;
public void otvoriopis(){
btnopis=(Button)findViewById(R.id.btnopis);
btnopis.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent otvoriopis= new Intent(MainActivity.this,Opis.class);
startActivity(otvoriopis);
}
});
}
public Button btnpronadi;
public void otvoripronadi(){
btnpronadi=(Button)findViewById(R.id.btnpronadi);
btnpronadi.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent otvoripronadi= new Intent(MainActivity.this,Pronadi.class);
startActivity(otvoripronadi);
}
});
}
public Button btnizlaz;
public void izlaz(){
btnizlaz=(Button)findViewById(R.id.btnizlaz);
btnizlaz.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
}
}
here is the manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shromid">
<application
android:allowBackup="true"
android:icon="@mipmap/app_ikona"
android:roundIcon="@mipmap/app_icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreen"
android:label="ShromID"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity android:name=".Opis" />
<activity android:name=".Pronadi"></activity>
</application>
</manifest>
java

add a comment |
I have problems with buttons.I have made 2 buttons that will when pressed open other activity(class).In code there is no error but when I launch emulator it just doesn't work and isn't opening those classes.
My button's btnopis and btnpronadi don't work(they are not opening other activity(class)).But I have button exit that Works and closes app. I don't get where the problem is. Here is the code
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
izlaz();
}
public Button btnopis;
public void otvoriopis(){
btnopis=(Button)findViewById(R.id.btnopis);
btnopis.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent otvoriopis= new Intent(MainActivity.this,Opis.class);
startActivity(otvoriopis);
}
});
}
public Button btnpronadi;
public void otvoripronadi(){
btnpronadi=(Button)findViewById(R.id.btnpronadi);
btnpronadi.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent otvoripronadi= new Intent(MainActivity.this,Pronadi.class);
startActivity(otvoripronadi);
}
});
}
public Button btnizlaz;
public void izlaz(){
btnizlaz=(Button)findViewById(R.id.btnizlaz);
btnizlaz.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
}
}
here is the manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shromid">
<application
android:allowBackup="true"
android:icon="@mipmap/app_ikona"
android:roundIcon="@mipmap/app_icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreen"
android:label="ShromID"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity android:name=".Opis" />
<activity android:name=".Pronadi"></activity>
</application>
</manifest>
java

Have you declared those activities in manifest?
– Saran Sankaran
Jan 29 '18 at 19:27
Yes I did, I will add manifest code now.
– M.Horvat
Jan 29 '18 at 19:27
No need for manifest. Check my answer
– Eduardo Herzer
Jan 29 '18 at 19:30
your methods are not working bro
– Vishal Yadav
Jan 29 '18 at 19:43
add a comment |
I have problems with buttons.I have made 2 buttons that will when pressed open other activity(class).In code there is no error but when I launch emulator it just doesn't work and isn't opening those classes.
My button's btnopis and btnpronadi don't work(they are not opening other activity(class)).But I have button exit that Works and closes app. I don't get where the problem is. Here is the code
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
izlaz();
}
public Button btnopis;
public void otvoriopis(){
btnopis=(Button)findViewById(R.id.btnopis);
btnopis.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent otvoriopis= new Intent(MainActivity.this,Opis.class);
startActivity(otvoriopis);
}
});
}
public Button btnpronadi;
public void otvoripronadi(){
btnpronadi=(Button)findViewById(R.id.btnpronadi);
btnpronadi.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent otvoripronadi= new Intent(MainActivity.this,Pronadi.class);
startActivity(otvoripronadi);
}
});
}
public Button btnizlaz;
public void izlaz(){
btnizlaz=(Button)findViewById(R.id.btnizlaz);
btnizlaz.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
}
}
here is the manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shromid">
<application
android:allowBackup="true"
android:icon="@mipmap/app_ikona"
android:roundIcon="@mipmap/app_icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreen"
android:label="ShromID"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity android:name=".Opis" />
<activity android:name=".Pronadi"></activity>
</application>
</manifest>
java

I have problems with buttons.I have made 2 buttons that will when pressed open other activity(class).In code there is no error but when I launch emulator it just doesn't work and isn't opening those classes.
My button's btnopis and btnpronadi don't work(they are not opening other activity(class)).But I have button exit that Works and closes app. I don't get where the problem is. Here is the code
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
izlaz();
}
public Button btnopis;
public void otvoriopis(){
btnopis=(Button)findViewById(R.id.btnopis);
btnopis.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent otvoriopis= new Intent(MainActivity.this,Opis.class);
startActivity(otvoriopis);
}
});
}
public Button btnpronadi;
public void otvoripronadi(){
btnpronadi=(Button)findViewById(R.id.btnpronadi);
btnpronadi.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent otvoripronadi= new Intent(MainActivity.this,Pronadi.class);
startActivity(otvoripronadi);
}
});
}
public Button btnizlaz;
public void izlaz(){
btnizlaz=(Button)findViewById(R.id.btnizlaz);
btnizlaz.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
}
}
here is the manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shromid">
<application
android:allowBackup="true"
android:icon="@mipmap/app_ikona"
android:roundIcon="@mipmap/app_icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreen"
android:label="ShromID"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity android:name=".Opis" />
<activity android:name=".Pronadi"></activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shromid">
<application
android:allowBackup="true"
android:icon="@mipmap/app_ikona"
android:roundIcon="@mipmap/app_icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreen"
android:label="ShromID"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity android:name=".Opis" />
<activity android:name=".Pronadi"></activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shromid">
<application
android:allowBackup="true"
android:icon="@mipmap/app_ikona"
android:roundIcon="@mipmap/app_icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreen"
android:label="ShromID"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity android:name=".Opis" />
<activity android:name=".Pronadi"></activity>
</application>
</manifest>
java

java

edited Jan 2 at 3:38
Cœur
19k9112154
19k9112154
asked Jan 29 '18 at 19:25
M.HorvatM.Horvat
55
55
Have you declared those activities in manifest?
– Saran Sankaran
Jan 29 '18 at 19:27
Yes I did, I will add manifest code now.
– M.Horvat
Jan 29 '18 at 19:27
No need for manifest. Check my answer
– Eduardo Herzer
Jan 29 '18 at 19:30
your methods are not working bro
– Vishal Yadav
Jan 29 '18 at 19:43
add a comment |
Have you declared those activities in manifest?
– Saran Sankaran
Jan 29 '18 at 19:27
Yes I did, I will add manifest code now.
– M.Horvat
Jan 29 '18 at 19:27
No need for manifest. Check my answer
– Eduardo Herzer
Jan 29 '18 at 19:30
your methods are not working bro
– Vishal Yadav
Jan 29 '18 at 19:43
Have you declared those activities in manifest?
– Saran Sankaran
Jan 29 '18 at 19:27
Have you declared those activities in manifest?
– Saran Sankaran
Jan 29 '18 at 19:27
Yes I did, I will add manifest code now.
– M.Horvat
Jan 29 '18 at 19:27
Yes I did, I will add manifest code now.
– M.Horvat
Jan 29 '18 at 19:27
No need for manifest. Check my answer
– Eduardo Herzer
Jan 29 '18 at 19:30
No need for manifest. Check my answer
– Eduardo Herzer
Jan 29 '18 at 19:30
your methods are not working bro
– Vishal Yadav
Jan 29 '18 at 19:43
your methods are not working bro
– Vishal Yadav
Jan 29 '18 at 19:43
add a comment |
2 Answers
2
active
oldest
votes
You forgot do call otvoriopis()
and otvoripronadi()
at onCreate
:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
izlaz();
otvoriopis();
otvoripronadi();
}
Oh,thank you very much. Now I get it! Thank you :)
– M.Horvat
Jan 29 '18 at 19:30
No problem. Glad to help. Please mark as answer =)
– Eduardo Herzer
Jan 29 '18 at 19:31
I can accept it in 8 minutes. As soon as I will be able to accept it, I'll do it :)
– M.Horvat
Jan 29 '18 at 19:32
add a comment |
You should call your functions in onCreate method, like you did for 'izlaz'
Oh thank you, now I understand it!
– M.Horvat
Jan 29 '18 at 19:30
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%2f48508566%2fandroid-button-not-opening-other-class%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 forgot do call otvoriopis()
and otvoripronadi()
at onCreate
:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
izlaz();
otvoriopis();
otvoripronadi();
}
Oh,thank you very much. Now I get it! Thank you :)
– M.Horvat
Jan 29 '18 at 19:30
No problem. Glad to help. Please mark as answer =)
– Eduardo Herzer
Jan 29 '18 at 19:31
I can accept it in 8 minutes. As soon as I will be able to accept it, I'll do it :)
– M.Horvat
Jan 29 '18 at 19:32
add a comment |
You forgot do call otvoriopis()
and otvoripronadi()
at onCreate
:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
izlaz();
otvoriopis();
otvoripronadi();
}
Oh,thank you very much. Now I get it! Thank you :)
– M.Horvat
Jan 29 '18 at 19:30
No problem. Glad to help. Please mark as answer =)
– Eduardo Herzer
Jan 29 '18 at 19:31
I can accept it in 8 minutes. As soon as I will be able to accept it, I'll do it :)
– M.Horvat
Jan 29 '18 at 19:32
add a comment |
You forgot do call otvoriopis()
and otvoripronadi()
at onCreate
:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
izlaz();
otvoriopis();
otvoripronadi();
}
You forgot do call otvoriopis()
and otvoripronadi()
at onCreate
:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
izlaz();
otvoriopis();
otvoripronadi();
}
answered Jan 29 '18 at 19:28
Eduardo HerzerEduardo Herzer
1,140919
1,140919
Oh,thank you very much. Now I get it! Thank you :)
– M.Horvat
Jan 29 '18 at 19:30
No problem. Glad to help. Please mark as answer =)
– Eduardo Herzer
Jan 29 '18 at 19:31
I can accept it in 8 minutes. As soon as I will be able to accept it, I'll do it :)
– M.Horvat
Jan 29 '18 at 19:32
add a comment |
Oh,thank you very much. Now I get it! Thank you :)
– M.Horvat
Jan 29 '18 at 19:30
No problem. Glad to help. Please mark as answer =)
– Eduardo Herzer
Jan 29 '18 at 19:31
I can accept it in 8 minutes. As soon as I will be able to accept it, I'll do it :)
– M.Horvat
Jan 29 '18 at 19:32
Oh,thank you very much. Now I get it! Thank you :)
– M.Horvat
Jan 29 '18 at 19:30
Oh,thank you very much. Now I get it! Thank you :)
– M.Horvat
Jan 29 '18 at 19:30
No problem. Glad to help. Please mark as answer =)
– Eduardo Herzer
Jan 29 '18 at 19:31
No problem. Glad to help. Please mark as answer =)
– Eduardo Herzer
Jan 29 '18 at 19:31
I can accept it in 8 minutes. As soon as I will be able to accept it, I'll do it :)
– M.Horvat
Jan 29 '18 at 19:32
I can accept it in 8 minutes. As soon as I will be able to accept it, I'll do it :)
– M.Horvat
Jan 29 '18 at 19:32
add a comment |
You should call your functions in onCreate method, like you did for 'izlaz'
Oh thank you, now I understand it!
– M.Horvat
Jan 29 '18 at 19:30
add a comment |
You should call your functions in onCreate method, like you did for 'izlaz'
Oh thank you, now I understand it!
– M.Horvat
Jan 29 '18 at 19:30
add a comment |
You should call your functions in onCreate method, like you did for 'izlaz'
You should call your functions in onCreate method, like you did for 'izlaz'
answered Jan 29 '18 at 19:28


VigenVigen
12619
12619
Oh thank you, now I understand it!
– M.Horvat
Jan 29 '18 at 19:30
add a comment |
Oh thank you, now I understand it!
– M.Horvat
Jan 29 '18 at 19:30
Oh thank you, now I understand it!
– M.Horvat
Jan 29 '18 at 19:30
Oh thank you, now I understand it!
– M.Horvat
Jan 29 '18 at 19:30
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%2f48508566%2fandroid-button-not-opening-other-class%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
Have you declared those activities in manifest?
– Saran Sankaran
Jan 29 '18 at 19:27
Yes I did, I will add manifest code now.
– M.Horvat
Jan 29 '18 at 19:27
No need for manifest. Check my answer
– Eduardo Herzer
Jan 29 '18 at 19:30
your methods are not working bro
– Vishal Yadav
Jan 29 '18 at 19:43