Intent in condition doesn't work - java

I have tried searching for this topic but i didn't find anything that would help me, so here I am asking this.
I am a beginner so I don't understand a lot of terms and if you answer my question please try to use simple language so I could understand.
I have a condition in that the elements at same position of two lists are compared and if they aren't equal than it jumps to another activity:
if (randomColors.get(i) != userColors.get(i)) {
Intent i = new Intent( GameActivity.this, GameOverActivity.class);
startActivity(i);
}
and it displays an error in debugging that I cannot solve:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gabie212.simonsays/com.gabie212.simonsays.GameOverActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
Please help me, I am a beginner and I don't know what's wrong with my code because I have done exactly as they taught us in class...
Here is the complete code
I know its not the best but its a work in proggress
package com.gabie212.simonsays;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.util.ArrayList;
public class GameActivity extends AppCompatActivity implements
View.OnClickListener {
private int i = 0;
private Thread t = new Thread();
private Button greenButton;
private Button redButton;
private Button blueButton;
private Button yellowButton;
private Button startButton;
private ArrayList<Integer> randomColors = new ArrayList<Integer>();
private ArrayList<Integer> userColors = new ArrayList<Integer>();
private GameManger gm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gm = new GameManger(this);
setContentView(R.layout.activity_game);
greenButton = (Button) findViewById(R.id.btnGreen);
redButton = (Button) findViewById(R.id.btnRed);
blueButton = (Button) findViewById(R.id.btnBlue);
yellowButton = (Button) findViewById(R.id.btnYellow);
startButton = (Button) findViewById(R.id.btnStart);
startButton.setOnClickListener(this);
greenButton.setOnClickListener(this);
redButton.setOnClickListener(this);
blueButton.setOnClickListener(this);
yellowButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
int num;
num= gm.getColor(4);
randomColors.add(num);
android.os.Handler handler = new android.os.Handler();
//TODO if the start button is pressed multiple times simultaneously it starts the lightup loop multiple times simultaneously
if (v.getId() == startButton.getId()) {
for (i = 0; i < randomColors.size(); i++) //light up loop
{
switch (randomColors.get(i)) {
case 1:
greenButton.setBackgroundResource(R.drawable.greenlightup);
handler.postDelayed(new Runnable()
{
#Override
public void run() {
// TODO Auto-generated method stub
greenButton.setBackgroundResource(R.drawable.green);
}
}, 2000);
break;
case 2:
redButton.setBackgroundResource(R.drawable.redlightup);
handler.postDelayed(new Runnable()
{
#Override
public void run() {
// TODO Auto-generated method stub
redButton.setBackgroundResource(R.drawable.red);
}
}, 2000);
break;
case 3:
blueButton.setBackgroundResource(R.drawable.bluelightup);
handler.postDelayed(new Runnable()
{
#Override
public void run() {
// TODO Auto-generated method stub
blueButton.setBackgroundResource(R.drawable.blue);
}
}, 2000);
break;
case 4:
yellowButton.setBackgroundResource(R.drawable.yellowlightup);
handler.postDelayed(new Runnable()
{
#Override
public void run() {
// TODO Auto-generated method stub
yellowButton.setBackgroundResource(R.drawable.yellow);
}
}, 2000);
break;
}
handler.postDelayed(new Runnable()
{
public void run() {
}
}, 2000);
}
for(i=0;i<randomColors.size();i++)
{
if(v.getId()==greenButton.getId())
{
userColors.add(1);
}
else
{
if(v.getId()==redButton.getId()){
userColors.add(2);
}
else
{
if(v.getId()==blueButton.getId())
{
userColors.add(3);
}
else
{
userColors.add(4);
}
}
}
}
for(i=0;i<randomColors.size();i++)
{
if(randomColors.get(i)!=userColors.get(i))
{
Intent i = new Intent( GameActivity.this, GameOverActivity.class);
startActivity(i);
}
}
}
}
}
by the its not a simple null pointer exception, at least i don't think so because there is nothing here to be null, there is only a simple intent in an if statement
here's the code for the game over activity
package com.gabie212.simonsays;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
public class GameOverActivity extends AppCompatActivity implements View.OnClickListener {
private Button againButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_over);
againButton = (Button) findViewById(R.id.btnStart);
againButton.setOnClickListener(this);
}
#Override
public void onClick(View view) {
Intent in = new Intent(GameOverActivity.this, GameActivity.class);
startActivity(in);
}
}
Thanks in advance.

In your GameOverActivity, on this line:
againButton = (Button) findViewById(R.id.btnStart);
Your againButton is null as you are referencing btnStart from your main activity layout (activity_game.xml). This can't be found because your GameOverActivity is using activity_game_over.xml for its layout:
setContentView(R.layout.activity_game_over);
Any views need to be defined within the activity_game_over.xml file for them to be used by the activity. You need to reference the ID of the button as defined in layout/activity_game_over.xml
againButton = (Button) findViewById(R.id.btnAgain); // Or whatver you've named it
As for your specific question as to why the Intent is not working, the Intent itself is working fine, it's just that GameOverActivity cannot start up properly due to the above issue, and therefore your app crashes.

Related

Text To Speech without textfield and button in Android Studio

So, I want to create a text to speech without the use of textfield and button in Android Studio. For example when I open the app it will say "WELCOME TO MY APP" without text field or any button. How can I do that? Need your help.
You could do like below:
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.speech.tts.TextToSpeech;
import java.util.Locale;
public class MainActivity extends Activity {
TextToSpeech t1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.ENGLISH);
}
}
});
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
t1.speak("welcome to my app", TextToSpeech.QUEUE_FLUSH, null);
}
}, 100);
}
public void onPause() {
if (t1 != null) {
t1.stop();
t1.shutdown();
}
super.onPause();
}
}
codes are self explanatory and I tested it with successful result.
Just add this in your onCreate():
myTTS = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
// replace this Locale with whatever you want
Locale localeToUse = new Locale("en","US");
myTTS.setLanguage(localeToUse);
myTTS.speak("Hi, Welcome to my app!", TextToSpeech.QUEUE_FLUSH, null);
}
}
});

project performs actions all at once

i am doing an android simon says app and i am in the light up loop,
for this example i have defined it so it would light up 4 colors because the array that has the numbers that light up the according numbers is 4 cells long
unfortunately it lights up all of the colors at the same time you could not distinguish the order i am trying to figure out why that is and how do imake it light up one color at once here's the code for my main activity and java calss that helps it
this is the activity:
package com.gabie212.simonsays;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.util.ArrayList;
public class GameActivity extends AppCompatActivity implements View.OnClickListener {
private int i = 0;
private Thread t = new Thread();
private Button greenButton;
private Button redButton;
private Button blueButton;
private Button yellowButton;
private Button startButton;
private ArrayList<Integer> randomColors = new ArrayList<Integer>();
private ArrayList<Integer> userColors = new ArrayList<Integer>();
private GameManger gm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gm = new GameManger(this);
setContentView(R.layout.activity_game);
greenButton = (Button) findViewById(R.id.btnGreen);
redButton = (Button) findViewById(R.id.btnRed);
blueButton = (Button) findViewById(R.id.btnBlue);
yellowButton = (Button) findViewById(R.id.btnYellow);
startButton = (Button) findViewById(R.id.btnStart);
startButton.setOnClickListener(this);
greenButton.setOnClickListener(this);
redButton.setOnClickListener(this);
blueButton.setOnClickListener(this);
yellowButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
int num;
for (i=0;i<3;i++) {
num = gm.getColor(4);
randomColors.add(num);
}
android.os.Handler handler = new android.os.Handler();
//TODO if the start button is pressed multiple times simultaneously it starts the lightup loop multiple times simultaneously
if (v.getId() == startButton.getId()) {
for (i = 0; i < randomColors.size(); i++) //light up loop
{
switch (randomColors.get(i)) {
case 1:
greenButton.setBackgroundResource(R.drawable.greenlightup);
handler.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
greenButton.setBackgroundResource(R.drawable.green);
}
}, 2000);
break;
case 2:
redButton.setBackgroundResource(R.drawable.redlightup);
handler.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
redButton.setBackgroundResource(R.drawable.red);
}
}, 2000);
break;
case 3:
blueButton.setBackgroundResource(R.drawable.bluelightup);
handler.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
blueButton.setBackgroundResource(R.drawable.blue);
}
}, 2000);
break;
case 4:
yellowButton.setBackgroundResource(R.drawable.yellowlightup);
handler.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
yellowButton.setBackgroundResource(R.drawable.yellow);
}
}, 2000);
break;
}
}
/*
for(i=0;i<randomColors.size();i++)
{
if(v.getId()==greenButton.getId())
{
userColors.add(1);
}
else
{
if(v.getId()==redButton.getId()){
userColors.add(2);
}
else
{
if(v.getId()==blueButton.getId())
{
userColors.add(3);
}
else
{
userColors.add(4);
}
}
}
}
for(i=0;i<randomColors.size();i++)
{
if(randomColors.get(i) != userColors.get(i))
{
Intent i = new Intent( GameActivity.this, GameOverActivity.class);
startActivity(i);
}
}
*/
}
}
}
and this is the java class:
package com.gabie212.simonsays;
import java.util.Random;
/**
* Created by Ronit on 21/02/2018.
*/
public class GameManger {
private GameActivity gActivity;
static Random rnd = new Random();
public GameManger(GameActivity mA)
{
this.gActivity =mA;
}
public int getColor(int size)
{
return rnd.nextInt(4)+1;
}
}
the part i had problems with is this part:
int num;
for (i=0;i<3;i++) {
num = gm.getColor(4);
randomColors.add(num);
}
android.os.Handler handler = new android.os.Handler();
//TODO if the start button is pressed multiple times simultaneously it starts the lightup loop multiple times simultaneously
if (v.getId() == startButton.getId()) {
for (i = 0; i < randomColors.size(); i++) //light up loop
{
switch (randomColors.get(i)) {
case 1:
greenButton.setBackgroundResource(R.drawable.greenlightup);
handler.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
greenButton.setBackgroundResource(R.drawable.green);
}
}, 2000);
break;
case 2:
redButton.setBackgroundResource(R.drawable.redlightup);
handler.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
redButton.setBackgroundResource(R.drawable.red);
}
}, 2000);
break;
case 3:
blueButton.setBackgroundResource(R.drawable.bluelightup);
handler.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
blueButton.setBackgroundResource(R.drawable.blue);
}
}, 2000);
break;
case 4:
yellowButton.setBackgroundResource(R.drawable.yellowlightup);
handler.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
yellowButton.setBackgroundResource(R.drawable.yellow);
}
}, 2000);
break;
}
as i mentioned it lights up the 4 buttons at once instead of doing it in an order and i using functions such as sleep didn't work and the delay mills i used either didn't seem to work either, how do i make it light up the colors in an order (i think its using sleep functions but i am not sure).
I think the problem is that you are starting multiple coroutines all at once (inside the for loop). I guess you are not very familiar with the Runnable interface: everytime a runnable is run, it runs in parallel to your main process, which means that your code keeps going no matter what.
It runs
greenButton.setBackgroundResource(R.drawable.greenlightup);
and sets a timer to run the delayed method. But while this method is waiting the for loop goes on, and
redButton.setBackgroundResource(R.drawable.redlightup);
is executed, and so forth. This is why your buttons are all colored at (almost) the same time. Your delayed methods all fire at (almost) the same time too!

how to get value through one class to another through intent?

i m new to android.i am trying to make a quiz app which has categories. i am passing different int value on click of each category i want to use that value in my Questionactivity class so that when first button is clicked only first 10 questions will run and on click of second button 10 to 20 questions will run.
package com.example.chaitanya.myquiz;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.concurrent.TimeUnit;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import static java.lang.Integer.parseInt;
public class QuestionActivity extends Activity {
List<Question> quesList;
int score = 0;
Random r = new Random();
Question currentQ;
TextView txtQuestion, times, scored;
Button button1, button2, button3;
CounterClass timer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent2 = getIntent();
int qid = intent2.getIntExtra("qid",10);
QuizHelper db = new QuizHelper(this); // my question bank class
quesList = db.getAllQuestions(); // this will fetch all quetonall
questions
currentQ = quesList.get(qid); // the current question
txtQuestion = (TextView) findViewById(R.id.txtQuestion);
// the textview in which the question will be displayed
// the three buttons,
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
// the textview in which score will be displayed
scored = (TextView) findViewById(R.id.score);
// the timer
times = (TextView) findViewById(R.id.timers);
// method which will set the things up for our game
setQuestionView();
times.setText("00:00:30");
// A timer of 30 seconds to play for, with an interval of 1 second (1000 milliseconds)
timer = new CounterClass(30000, 1000);
timer.start();
// button click listeners
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// passing the button text to other method
// to check whether the anser is correct or not
// same for all three buttons
getAnswer(button1.getText().toString());
}
});
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getAnswer(button2.getText().toString());
}
});
button3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getAnswer(button3.getText().toString());
}
});
}
public void getAnswer(String AnswerString) {
Intent intent2 = getIntent();
int qid = intent2.getIntExtra("qid", 10);
if (currentQ.getANSWER().equals(AnswerString)) {
// if conditions matches increase the int (score) by 1
// and set the text of the score view
score++;
scored.setText("Score : " + score);
} else {
// if unlucky start activity and finish the game
timer.cancel();
Intent intent = new Intent(QuestionActivity.this,
ResultActivity.class);
// passing the int value
Bundle b = new Bundle();
b.putInt("score", score); // Your score
intent.putExtras(b); // Put your score to your next
startActivity(intent);
finish();
}
if (qid < 60) {
// if questions are not over then do this
currentQ = quesList.get(qid);
setQuestionView();
} else {
// if over do this
timer.cancel();
Intent intent = new Intent(QuestionActivity.this,
ResultActivity.class);
Bundle b = new Bundle();
b.putInt("score", score); // Your score
intent.putExtras(b); // Put your score to your next
startActivity(intent);
finish();
}
}
#TargetApi(Build.VERSION_CODES.GINGERBREAD)
#SuppressLint("NewApi")
public class CounterClass extends CountDownTimer {
public CounterClass(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
#Override
public void onFinish() {
times.setText("Time is up");
Intent intent = new Intent(QuestionActivity.this,
ResultActivity.class);
timer.cancel();
Bundle b = new Bundle();
b.putInt("score", score); // Your score
intent.putExtras(b); // Put your score to your next
startActivity(intent);
finish();
}
#Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
long millis = millisUntilFinished;
String hms = String.format(
"%02d:%02d:%02d",
TimeUnit.MILLISECONDS.toHours(millis),
TimeUnit.MILLISECONDS.toMinutes(millis)
- TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
.toHours(millis)),
TimeUnit.MILLISECONDS.toSeconds(millis)
-
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
.toMinutes(millis)));
System.out.println(hms);
times.setText(hms);
}
}
private void setQuestionView() {
Random r = new Random();
Intent intent2 = getIntent();
int qid = intent2.getIntExtra("qid", 10);
switch (qid) {
case 10:
// the method which will put all things together
txtQuestion.setText(currentQ.getQUESTION());
button1.setText(currentQ.getOPTA());
button2.setText(currentQ.getOPTB());
button3.setText(currentQ.getOPTC());
qid = (r.nextInt(10) + 1);
case 20:
txtQuestion.setText(currentQ.getQUESTION());
button1.setText(currentQ.getOPTA());
button2.setText(currentQ.getOPTB());
button3.setText(currentQ.getOPTC());
qid = (r.nextInt(20) + 11);
case 30:
txtQuestion.setText(currentQ.getQUESTION());
button1.setText(currentQ.getOPTA());
button2.setText(currentQ.getOPTB());
button3.setText(currentQ.getOPTC());
qid = (r.nextInt(30) + 21);
}
}
}
You need Internet permission to access network.
Add these permissions to your AndroidManifest.xml.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Details: https://developer.android.com/training/basics/network-ops/connecting.html
the exception is raised from null pointer, the starting intent of your activity has no extra bundle
java.lang.NullPointerException: Attempt to
invoke virtual method 'double
android.os.Bundle.getDouble(java.lang.String)' on a null
object reference
at
com.example.chaitanya.calculatornew.
MainActivity.findtheweather(MainActivity.java:27)

How to implement "turn off music" button Android

I want to add a button in my application that turns off the music but I don't know how to approach it, I have an idea but I'm sure it's far from best so I want to consult with you. The situation is as follows:
public class MainActivity extends Activity implements OnClickListener {
MediaPlayer easysong;
MediaPlayer normalsong;
MediaPlayer hardsong;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.land_main);
mContext = this;
restartButton = (Button)findViewById(R.id.restartButton);
restartButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
easysong = MediaPlayer.create(MainActivity.this, R.raw.arideniro);
normalsong = MediaPlayer.create(MainActivity.this, R.raw.junior);
hardsong = MediaPlayer.create(MainActivity.this, R.raw.ketsathis);
counter = 101;
i = 500 - dif;
new Thread(new Runnable() {
public void run() {
if(i==500){
easysong.start();}
else if(i==375){
normalsong.start();
}else if(i==250){
hardsong.start();
}
while (counter > 0) {
try {
Thread.sleep(i);
} catch (InterruptedException e) {
e.printStackTrace();
}
counter--;
runOnUiThread(new Runnable() {
#Override
public void run() {
scoreText.setText(Integer.toString(counter));
}
});
if(i>150){
i/=1.01;}
else if(i>90-(dif/10)){
i-=1;
}
}if (counter==0) {
mChronometer.stop();
if(easysong.isPlaying()) {
easysong.stop();
easysong.release();
easysong = null;
}else if(normalsong.isPlaying()){
normalsong.stop();
normalsong.release();
normalsong = null;
}else if(hardsong.isPlaying()){
hardsong.stop();
hardsong.release();
hardsong = null;
}
This is the main class of my app where the mediaplayer is used, now I deleted much of the code because it was irrelevant to the mediaplayer and the question, so don't look for the missing brackets and such. And this here is the main menu class where the Switch that will turn on and off the music will be located:
public class MainMenu extends Activity{
private Button easy;
private Button normal;
private Button hard;
private Button scores;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
easy = (Button) findViewById(R.id.btn_easy);
scores = (Button) findViewById(R.id.btn_highscores);
easy.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dif = 0;
startGame();
}
});
}
public void startGame() {
Intent intent = new Intent(MainMenu.this, MainActivity.class);
startActivity(intent);
}
So my idea is simnple, to add a variable in MainActivity like "int p;" and from the MainMenu class to change it's state between 0 and 1, then I will add around each line that starts music an if(p==1) but is this a good approach ? Also I would like the value of the int to be saved when the app is closed

java.lang.UnsupportedOperationException error on splashscreen.java

I keep getting this errors related to Thread.stop() in splashscreen.java. I'm pretty new at it and aware of deprecated Thread.stop() but can someone please explain what I'm doing wrong here, thanks..
java.lang.UnsupportedOperationException
at java.lang.Thread.stop(Thread.java:1076)
at java.lang.Thread.stop(Thread.java:1063)
at com.dapp.d.SplashScreen$4.run(SplashScreen.java:88)
This is full source code of splashscreen.java
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
public class SplashScreen extends Activity {
private boolean active = true;
private int splashTime = 3000;
private boolean clickFlag = true;
private Thread splashTread = null;
private Button btnHelp;
private Button btnAboutUs;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.splashRelativeLayout);
relativeLayout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Uri uri = Uri.parse("http://www.exmaple.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
btnAboutUs = (Button)findViewById(R.id.btnAboutus);
btnHelp = (Button)findViewById(R.id.btnHelp);
try{
btnAboutUs.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
clickFlag = false;
splashTread.stop(); <<<<<<<<<<<<<<<<<<< line 49
Intent intent = new Intent();
intent.setClass(getApplicationContext(), AboutUs.class);
startActivity(intent);
SplashScreen.this.finish();
}
});
btnHelp.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
clickFlag = false;
splashTread.stop(); <<<<<<<<<<<<<<<<<<< line 63
Intent intent = new Intent();
intent.setClass(getApplicationContext(), HelpActivity.class);
startActivity(intent);
SplashScreen.this.finish();
}
});
splashTread = new Thread() {
#Override
public void run() {
try{
int waited = 0;
while(active && (waited < splashTime)) {
sleep(100);
waited += 100;
}
} catch(InterruptedException e) {
// do nothing
}finally {
if(clickFlag){
Intent intent=new Intent();
intent.setClass(getApplicationContext(), SearchWord.class);
startActivity(intent);
finish();
stop(); <<<<<<<<<<<<<<< line 88
}else{
finish();
stop();
}
}
}
};
splashTread.start();
}catch (Exception e) {
// TODO: handle exception
}
}
}
I don't think you need to call stop there at all. Your thread doesn't loop so it will execute and end normally. Try just removing the stop();
I had a similar problem and the solution is to wrap the stop method in a try/catch statment and in the catch use Throwable t.
It will work.

Categories

Resources