Splitting up classes from class and calling methods
I have created an application using the texttospeech api and I have all the functionality within one class. I would like to split this into several classes but when I do so I have a null exception error.
The texttospeech api has onclick buttons. Within these buttons I try to call a method from another class for the functionality.
I extend the class 1 with the current class I am using.
I then add the method image() within the class 1:
public void image() {
if(currentHelloIndex==0){
alertDialog.show();
}
else if (currentHelloIndex == 2) {
Image.setImageResource(R.drawable.books);
} else if (currentHelloIndex == 3) {
Image.setImageResource(R.drawable.mic);
}
Currently no variables are declared in class 1 as it is using the variables in the main class.
I then call this method in the main class. This doesn't seem to be working the class 1 has no onCreate method it is just a standard class which extends the main class.
I would appreciate any help on this as I need to separate the functionality into separate classes.
Edit:
currentHelloIndex is an int which is set to 0 in the main class if the button is clicked an currentHelloIndex is 0 an al开发者_JAVA技巧ertdialog in the main class will appear if the button is clicked and currentHelloIndex is 2 this will set the Image which is an ImageView in the main class with the image set.
I have put into the main class: static SoundGameScore sound;
Within the main class I have called sound.Image(); in an onclick. Please can someone let me know what I have done wrong, thanks.
You should use some of the refactoring functionality in your Java IDE (you ARE using a Java IDE, right?)
精彩评论