Android button not opening other class












0















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>












share|improve this question

























  • 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
















0















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>












share|improve this question

























  • 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














0












0








0








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>












share|improve this question
















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 android button






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












2 Answers
2






active

oldest

votes


















0














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();
}





share|improve this answer
























  • 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



















0














You should call your functions in onCreate method, like you did for 'izlaz'






share|improve this answer
























  • Oh thank you, now I understand it!

    – M.Horvat
    Jan 29 '18 at 19:30













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
});


}
});














draft saved

draft discarded


















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









0














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();
}





share|improve this answer
























  • 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
















0














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();
}





share|improve this answer
























  • 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














0












0








0







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();
}





share|improve this answer













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();
}






share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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













0














You should call your functions in onCreate method, like you did for 'izlaz'






share|improve this answer
























  • Oh thank you, now I understand it!

    – M.Horvat
    Jan 29 '18 at 19:30


















0














You should call your functions in onCreate method, like you did for 'izlaz'






share|improve this answer
























  • Oh thank you, now I understand it!

    – M.Horvat
    Jan 29 '18 at 19:30
















0












0








0







You should call your functions in onCreate method, like you did for 'izlaz'






share|improve this answer













You should call your functions in onCreate method, like you did for 'izlaz'







share|improve this answer












share|improve this answer



share|improve this answer










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





















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith