Android: Carrying EditText over to new intent and inserting into TextView - java

I'm trying to make it so that once the user enters there name into the given EditText then accesses guessing game from the main menu it redirects you to new Activity in this case the Guessing game but it will not carry over the Information To TextView.
Here is my Code for GameMenu.java:
public class GameMenu extends Activity {
private static final int REQUEST_CODE = 10;
// TextViews
TextView Help;
// String's
String GameSelec;
//Intent
Intent Intent;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gamemenu);
Help = (TextView) findViewById(R.id.TextHelp);
Help.setVisibility(View.INVISIBLE);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menuoptions, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
case R.id.help:
Help = (TextView) findViewById(R.id.TextHelp);
Help.setText("Enter your name and Select game to play");
Help.setVisibility(View.VISIBLE);
Handler handle = new Handler();
handle.postDelayed(new Runnable() {
#Override
public void run() {
Help.setVisibility(View.INVISIBLE);
}
}, 10000);
return true;
case R.id.GuesGame:
Toast.makeText(this, "Redirecting Now",
Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(GameMenu.this, GuessGame.class);
EditText EditName = (EditText) findViewById(R.id.EditName);
myIntent.putExtra("Name", EditName.getText().toString());
startActivityForResult(myIntent, REQUEST_CODE);
return true;
case R.id.Game2:
Toast.makeText(this, "In Development",
Toast.LENGTH_LONG).show();
return true;
case R.id.Game3:
Toast.makeText(this, "In Development",
Toast.LENGTH_LONG).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Then this is my gamemenu.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".GameMenu" >
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alignmentMode="alignBounds"
android:columnCount="2"
android:columnOrderPreserved="false"
android:rowCount="14"
android:useDefaultMargins="true" >
<TextView
android:id="#+id/Gamemenu"
android:layout_column="1"
android:layout_gravity="center_horizontal|top"
android:layout_row="1"
android:text="Game Menu: Follow Instructions"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/GameInsruct"
android:layout_column="1"
android:layout_gravity="center_horizontal|top"
android:layout_row="2"
android:text="Please enter name and select game"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/EditName"
android:layout_column="1"
android:layout_gravity="left|top"
android:layout_row="3"
android:ems="10"
android:hint="Your name here"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/TextMessage"
android:layout_column="1"
android:layout_gravity="center"
android:layout_row="13"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/TextHelp"
android:layout_column="1"
android:layout_gravity="center_horizontal|top"
android:layout_row="13"
android:text="Help"
android:textAppearance="?android:attr/textAppearanceMedium" />
</GridLayout>
</LinearLayout>
Then GuessGame.java:
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class GuessGame extends Activity {
// TextViews
TextView Welcome;
TextView Txtname;
TextView Txtnumber;
// EditViews
EditText EdtName;
EditText EditNum1;
EditText EditNum2;
EditText EditGuess;
// Buttons
Button BtnDisp;
// RadioGroup-Related
private RadioGroup radioGroup;
private RadioButton easy, medium, hard;
// int's
int Max;
int max;
int random;
int Attempts;
int guess;
int num1;
// Strings
String name;
String result;
String Strngnum1;
String NameExtra;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
Intent Intent = getIntent();
if (Intent.hasExtra(NameExtra)){
TextView setName = (TextView) findViewById(R.id.EdtName);
String NameExtra = Intent.getStringExtra("Player");
setName.setText("Player:" + NameExtra + "Have Fun");
}
//name = NameExtra;
/*Bundle extras = getIntent().getExtras();
if (extras !=null) {
NameExtra = extras.getString("Name");
if (NameExtra != null) {
TextView setName = (TextView) findViewById(R.id.EditName);
setName.setText("Player:" + NameExtra + "Have Fun");
name = NameExtra;
}
}
*/
/*
*/
Attempts = Attempts + 3;
//EditName = (EditText) findViewById(R.id.EdtName);
EditNum1 = (EditText) findViewById(R.id.EdtNum1);
Txtname = (TextView) findViewById(R.id.UserDisp);
radioGroup = (RadioGroup) findViewById(R.id.myRadioGroup);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// find which radio button is selected
if (checkedId == R.id.Easy) {
Toast.makeText(getApplicationContext(), "Choice: 1-5",
Toast.LENGTH_SHORT).show();
} else if (checkedId == R.id.Medium) {
Toast.makeText(getApplicationContext(), "Choice: 1-10",
Toast.LENGTH_SHORT).show();
} else if (checkedId == R.id.Hard) {
Toast.makeText(getApplicationContext(), "Choice: 1-20",
Toast.LENGTH_SHORT).show();
}
}
});
easy = (RadioButton) findViewById(R.id.Easy);
medium = (RadioButton) findViewById(R.id.Medium);
hard = (RadioButton) findViewById(R.id.Hard);
}
public void Start(View StartDisp) {
int selectedId = radioGroup.getCheckedRadioButtonId();
//Txtname = (TextView) findViewById(R.id.UserDisp);
//Txtname.setText(name);
// find which radio Button is checked by id
if (selectedId == easy.getId()) {
Toast.makeText(getApplicationContext(), "You Chose 'Easy' '1-5'",
Toast.LENGTH_LONG).show();
getWindow().getDecorView().setBackgroundColor(
Color.parseColor("#abf234"));
max = 5;
} else if (selectedId == medium.getId()) {
Toast.makeText(getApplicationContext(),
"You Chose 'Medium' '1-10'", Toast.LENGTH_LONG).show();
getWindow().getDecorView().setBackgroundColor(
Color.parseColor("#E8A317"));
max = 10;
} else {
Toast.makeText(getApplicationContext(), "You Chose 'Hard' '1-20'",
Toast.LENGTH_LONG).show();
getWindow().getDecorView().setBackgroundColor(
Color.parseColor("#FF0000"));
max = 20;
}
random = RandomNumber(max);
//Txtname.setText(name + random );
Txtname = new TextView(this);
Txtnumber = new TextView(this);
TextView DispInform = new TextView(this);
EdtName = (EditText) findViewById(R.id.EdtName);
EditNum1 = (EditText) findViewById(R.id.EdtNum1);
Txtname = (TextView) findViewById(R.id.UserDisp);
Txtname = (TextView) findViewById(R.id.EditName);
Txtname.setText(name);
Txtnumber =(TextView) findViewById(R.id.EdtNum1);
num1 = Integer.parseInt(Txtnumber.getText().toString());
Strngnum1 = String.valueOf(num1);
StringBuilder StrngBuild = new StringBuilder();
StrngBuild.append(name);
StrngBuild.append(" You have Chosen the number");
StrngBuild.append(Strngnum1);
line 181 StrngBuild.append(random);
DispInform = (TextView) findViewById(R.id.DispAll);
DispInform.setText(StrngBuild);
}
public void Guess(View BtnGuess) {
TextView tvResult = (TextView) findViewById(R.id.tvResult);
if (Attempts > 0) {
EditGuess = (EditText) findViewById(R.id.EdtGuess);
guess = Integer.parseInt(EditGuess.getText().toString());
if (guess == random) {
result = "Correct";
tvResult.setText(result);
getWindow().getDecorView().setBackgroundColor(
Color.parseColor("#FFFFFF"));
}
else if ((guess + 3 == random) || (guess - 3 == random)) {
Attempts = Attempts - 1;
result = "Almost There";
tvResult.setText(result);
}
else if (guess - 6 == random) {
Attempts = Attempts - 1;
result = "Sky High that one";
tvResult.setText(result);
}
else if (guess + 6 == random) {
Attempts = Attempts - 1;
result = "Low blow guess that one";
tvResult.setText(result);
}
else
{
Attempts = Attempts - 1;
}
} else if (Attempts == 0) {
Toast.makeText(getApplicationContext(), "Out Of Attempts",
Toast.LENGTH_LONG).show();
getWindow().getDecorView().setBackgroundColor(
Color.parseColor("#43C6DB"));
}
}
public int RandomNumber(int Max) {
int random = 1 + (int) (Math.random() * ((Max - 1) - 1));
return random;
}
/*
* public void generateRandom() { random =
* Min+(int)(Math.random()*((Max-Min) + 1));
*
* if(random > Max || random < Min) { generateRandom(); }
*
* }
*/
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.gamemain, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
game.xml:
<TextView
android:id="#+id/Welcome"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_gravity="left"
android:layout_row="1"
android:text="Welcome:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/EntrNum"
android:layout_width="167dp"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="left"
android:layout_row="3"
android:layout_rowSpan="2"
android:text="Please enter a number between 1 - 20"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/EdtName"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="left|bottom"
android:layout_row="6"
android:ems="10"
android:hint="Name"
android:text="" >
</TextView>
<EditText
android:id="#+id/EdtNum1"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="left"
android:layout_row="8"
android:ems="10"
android:hint="Number"
android:inputType="number" >
<requestFocus />
</EditText>
<RadioGroup
android:id="#+id/myRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text"
android:checkedButton="#+id/sound" >
<RadioButton
android:id="#+id/Easy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1-5" />
<RadioButton
android:id="#+id/Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1-10" />
<RadioButton
android:id="#+id/Hard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1-20" />
</RadioGroup>
<Space
android:layout_width="32dp"
android:layout_height="1dp"
android:layout_column="0"
android:layout_row="0" />
<Space
android:layout_width="1dp"
android:layout_height="32dp"
android:layout_column="0"
android:layout_row="0" />
<EditText
android:id="#+id/EdtGuess"
android:layout_width="157dp"
android:layout_column="1"
android:layout_gravity="left"
android:layout_row="15"
android:ems="10"
android:hint="Take A Guess"
android:inputType="number" />
<Button
android:id="#+id/StartDisp"
android:layout_width="164dp"
android:layout_height="83dp"
android:layout_column="2"
android:layout_columnSpan="2"
android:layout_gravity="left"
android:layout_row="14"
android:onClick="Start"
android:text="Start Game" />
<Button
android:id="#+id/BtnGuess"
android:layout_width="131dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="right|top"
android:layout_row="17"
android:onClick="Guess"
android:text="Guess" />
<Space
android:layout_width="226dp"
android:layout_height="1dp"
android:layout_column="6"
android:layout_row="0" />
<Space
android:layout_width="1dp"
android:layout_height="16dp"
android:layout_column="0"
android:layout_row="2" />
<Space
android:layout_width="1dp"
android:layout_height="16dp"
android:layout_column="0"
android:layout_row="7" />
<Space
android:layout_width="1dp"
android:layout_height="16dp"
android:layout_column="0"
android:layout_row="9" />
<Space
android:layout_width="1dp"
android:layout_height="2dp"
android:layout_column="0"
android:layout_row="10" />
<Space
android:layout_width="1dp"
android:layout_height="2dp"
android:layout_column="0"
android:layout_row="11" />
<Space
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_column="0"
android:layout_row="12" />
<Space
android:layout_width="1dp"
android:layout_height="2dp"
android:layout_column="0"
android:layout_row="13" />
<Space
android:layout_width="1dp"
android:layout_height="78dp"
android:layout_column="0"
android:layout_row="15" />
<Space
android:layout_width="1dp"
android:layout_height="219dp"
android:layout_column="0"
android:layout_row="17" />
<Space
android:layout_width="1dp"
android:layout_height="53dp"
android:layout_column="0"
android:layout_row="14" />
<Space
android:layout_width="111dp"
android:layout_height="1dp"
android:layout_column="1"
android:layout_row="0" />
<Space
android:layout_width="77dp"
android:layout_height="1dp"
android:layout_column="2"
android:layout_row="0" />
<Space
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_column="2"
android:layout_row="4" />
<Space
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_column="2"
android:layout_row="4" />
<Space
android:layout_width="100dp"
android:layout_height="128dp"
android:layout_column="2"
android:layout_row="4" />
<Space
android:layout_width="100dp"
android:layout_height="162dp"
android:layout_column="2"
android:layout_row="4" />
<Space
android:layout_width="100dp"
android:layout_height="196dp"
android:layout_row="4" />
<TextView
android:id="#+id/tvResult"
android:layout_column="1"
android:layout_gravity="left|top"
android:layout_row="16"
android:text="result" />
<TextView
android:id="#+id/DispAll"
android:layout_height="wrap_content"
android:layout_column="6"
android:layout_gravity="right|top"
android:layout_row="5"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/BtnReturn"
android:layout_column="1"
android:layout_gravity="left|center_vertical"
android:layout_row="17"
android:text="Return To Home Screen" />
<TextView
android:id="#+id/UserDisp"
android:layout_column="2"
android:layout_gravity="right|center_vertical"
android:layout_row="4"
android:textAppearance="?android:attr/textAppearanceLarge" />
</GridLayout>
It would be very helpful and much appreciated if you can help my solve this problem also another issue is whenever i am on the GuessingGame and attempt to start my app crashes and this is the LogCat Error window from it:
03-15 14:48:56.350: E/AndroidRuntime(1397): FATAL EXCEPTION: main
03-15 14:48:56.350: E/AndroidRuntime(1397): Process: com.Lewis.c3383583task3, PID: 1397
03-15 14:48:56.350: E/AndroidRuntime(1397): java.lang.IllegalStateException: Could not execute method of the activity
03-15 14:48:56.350: E/AndroidRuntime(1397): at android.view.View$1.onClick(View.java:3823)
03-15 14:48:56.350: E/AndroidRuntime(1397): at android.view.View.performClick(View.java:4438)
03-15 14:48:56.350: E/AndroidRuntime(1397): at android.view.View$PerformClick.run(View.java:18422)
03-15 14:48:56.350: E/AndroidRuntime(1397): at android.os.Handler.handleCallback(Handler.java:733)
03-15 14:48:56.350: E/AndroidRuntime(1397): at android.os.Handler.dispatchMessage(Handler.java:95)
03-15 14:48:56.350: E/AndroidRuntime(1397): at android.os.Looper.loop(Looper.java:136)
03-15 14:48:56.350: E/AndroidRuntime(1397): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-15 14:48:56.350: E/AndroidRuntime(1397): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 14:48:56.350: E/AndroidRuntime(1397): at java.lang.reflect.Method.invoke(Method.java:515)
03-15 14:48:56.350: E/AndroidRuntime(1397): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-15 14:48:56.350: E/AndroidRuntime(1397): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-15 14:48:56.350: E/AndroidRuntime(1397): at dalvik.system.NativeStart.main(Native Method)
03-15 14:48:56.350: E/AndroidRuntime(1397): Caused by: java.lang.reflect.InvocationTargetException
03-15 14:48:56.350: E/AndroidRuntime(1397): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 14:48:56.350: E/AndroidRuntime(1397): at java.lang.reflect.Method.invoke(Method.java:515)
03-15 14:48:56.350: E/AndroidRuntime(1397): at android.view.View$1.onClick(View.java:3818)
03-15 14:48:56.350: E/AndroidRuntime(1397): ... 11 more
03-15 14:48:56.350: E/AndroidRuntime(1397): Caused by: java.lang.NullPointerException
03-15 14:48:56.350: E/AndroidRuntime(1397): at com.Lewis.c3383583task3.GuessGame.Start(GuessGame.java:181)
03-15 14:48:56.350: E/AndroidRuntime(1397): ... 14 more
if you see anything that you think could be an issue please tell me thanks.

Related

Android: 3 activities with the same code but 1 crashes all the time

I am building a math app that has timed multiple choice questions for addition, subtraction, multiplication, and division. The code is pretty simple and is the same for each activity. However, My subtraction activity is very buggy and always crashes at random times. Sometimes it will crash after pressing GO, sometimes it crashes after choosing the first answer, sometimes I can get to 3 questions then it crashes. I'm confused because it does not happen with addition or multiplication. I'm wondering if it has something to do with memory?
Anyways, here is my code and error. Thanks in advance!
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.*;
public class subActivity extends AppCompatActivity {
Button button0;
Button button1;
Button button2;
Button button3;
TextView sub;
Button startButton;
TextView resultTextView;
TextView pointsTextView;
ArrayList<Integer> answers = new ArrayList<Integer>();
int locationOfCorrectAnswer;
int score = 0;
int numberOfQuestions = 0;
TextView timerTextView;
Button playAgainButton;
RelativeLayout gameRelativeLayout;
GridLayout buttonLayout;
float percent;
public void playAgain(View view){
score = 0;
numberOfQuestions = 0;
timerTextView.setText("30s");
pointsTextView.setText("0/0");
resultTextView.setText("");
playAgainButton.setVisibility(View.INVISIBLE);
generateQuestion();
new CountDownTimer(30100, 1000) {
#Override
public void onTick(long millisUntilFinished) {
buttonLayout.setVisibility(View.VISIBLE);
sub.setVisibility(View.VISIBLE);
timerTextView.setText(String.valueOf(millisUntilFinished/1000) + "s");
}
#Override
public void onFinish() {
playAgainButton.setVisibility(View.VISIBLE);
timerTextView.setText("0s");
resultTextView.setText("Your score:" + percent + "%\n Questions:" + Integer.toString(score) + "/" + numberOfQuestions);
buttonLayout.setVisibility(View.INVISIBLE);
sub.setVisibility(View.INVISIBLE);
}
}.start();
}
public void generateQuestion() {
Random rand = new Random();
int a = rand.nextInt(21);
int b = rand.nextInt(21);
int incorrectAnswer;
sub.setText(a + " - " + b);
locationOfCorrectAnswer = rand.nextInt(4);
answers.clear();
for (int i=0; i<4;i++){
if(i == locationOfCorrectAnswer){
answers.add(a-b);
}
else{
incorrectAnswer = rand.nextInt((a-b));
while (incorrectAnswer == a-b) {
incorrectAnswer = rand.nextInt((a-b));
}
answers.add(incorrectAnswer);
}
}
button0.setText(Integer.toString(answers.get(0)));
button1.setText(Integer.toString(answers.get(1)));
button2.setText(Integer.toString(answers.get(2)));
button3.setText(Integer.toString(answers.get(3)));
}
public void start(View view) {
startButton.setVisibility(View.INVISIBLE);
gameRelativeLayout.setVisibility(RelativeLayout.VISIBLE);
playAgain(findViewById(R.id.playAgain));
}
public void chooseAnswer(View view) {
if (view.getTag().toString().equals(Integer.toString(locationOfCorrectAnswer))) {
score++;
resultTextView.bringToFront();
resultTextView.setText("Correct!");
//resultTextView.setBackgroundColor(-16711936);
} else {
resultTextView.bringToFront();
resultTextView.setText("Incorrect!");
//resultTextView.setBackgroundColor(-65536);
}
numberOfQuestions++;
pointsTextView.setText(Integer.toString(score) + "/" + numberOfQuestions);
percent = Math.round((score/(float)numberOfQuestions)*100.0); //get the percentage recieved
generateQuestion();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub);
startButton = (Button) findViewById(R.id.goButton);
sub = (TextView) findViewById(R.id.subTextView);
resultTextView = (TextView) findViewById(R.id.resultTextView);
pointsTextView = (TextView) findViewById(R.id.pointsTextView);
button0 = (Button) findViewById(R.id.button0);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
timerTextView = (TextView) findViewById(R.id.timerTextView);
playAgainButton = (Button) findViewById(R.id.playAgain);
gameRelativeLayout = (RelativeLayout) findViewById(R.id.gameRelativeLayout);
buttonLayout = (GridLayout) findViewById(R.id.buttonLayout);
}
}
This error shows up when it crashes:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jimmy.mathtime, PID: 14678
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5224)
at android.view.View$PerformClick.run(View.java:21356)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5585)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5224) 
at android.view.View$PerformClick.run(View.java:21356) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5585) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
Caused by: java.lang.IllegalArgumentException: n <= 0: -1
at java.util.Random.nextInt(Random.java:182)
at com.example.jimmy.mathtime.subActivity.generateQuestion(subActivity.java:84)
at com.example.jimmy.mathtime.subActivity.chooseAnswer(subActivity.java:124)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
at android.view.View.performClick(View.java:5224) 
at android.view.View$PerformClick.run(View.java:21356) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5585) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
My XML file:
<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jimmy.mathtime.subActivity">
<RelativeLayout
android:id="#+id/gameRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible">
<GridLayout
android:id="#+id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/subTextView">
<Button
android:id="#+id/button0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_row="0"
android:layout_rowWeight="1"
android:background="#android:color/holo_blue_bright"
android:onClick="chooseAnswer"
android:tag="0"
android:text="#string/_3"
android:textSize="80sp" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_row="0"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:onClick="chooseAnswer"
android:tag="1"
android:text="#string/_3"
android:textSize="80sp" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_row="1"
android:layout_rowWeight="1"
android:background="#android:color/holo_green_light"
android:onClick="chooseAnswer"
android:tag="2"
android:text="#string/_3"
android:textSize="80sp" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_row="1"
android:layout_rowWeight="1"
android:background="#android:color/holo_purple"
android:onClick="chooseAnswer"
android:tag="3"
android:text="#string/_3"
android:textSize="80sp" />
</GridLayout>
<TextView
android:id="#+id/subTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/timerTextView"
android:layout_centerHorizontal="true"
android:layout_marginTop="36dp"
android:padding="10dp"
android:text="#string/_3_x_3"
android:textColor="#android:color/black"
android:textSize="50sp"
android:textStyle="bold" />
<TextView
android:id="#+id/timerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="15dp"
android:layout_marginTop="14dp"
android:padding="10dp"
android:text="#string/_30s"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="#+id/playAgain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/buttonLayout"
android:layout_centerHorizontal="true"
android:layout_marginBottom="65dp"
android:background="#color/colorPrimary"
android:onClick="playAgain"
android:text="Play_again"
android:textSize="30sp"
android:visibility="invisible" />
<TextView
android:id="#+id/pointsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/timerTextView"
android:layout_marginEnd="16dp"
android:padding="10dp"
android:text="#string/_0_0"
android:textSize="30sp"
android:textStyle="bold"
tools:ignore="RelativeOverlap" />
<TextView
android:id="#+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:padding="20dp"
android:text="#string/correct"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
<Button
android:id="#+id/goButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:backgroundTint="#android:color/holo_blue_bright"
android:onClick="start"
android:padding="40dp"
android:text="#string/go"
android:textSize="80sp"
android:visibility="visible" />
</android.widget.RelativeLayout>
Your exception states:
Caused by: java.lang.IllegalArgumentException: n <= 0: -1
at java.util.Random.nextInt(Random.java:182)
at com.example.jimmy.mathtime.subActivity.generateQuestion(subActivity.java:84)
Basically you pass a negative value to rand.nextInt(max) method.
In your code you do the following operation:
incorrectAnswer = rand.nextInt((a-b));
If b is greater than a, you pass a negative number to nextInt function. This causes your problem. It is not allowed to do this. Check if (a-b)>0!

Android Studio Program Crash

I have two activities Main, and Game_Activity
When my app launches and I click a button to take me to the Game_Activity it crashes...
Main
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnHelp = (Button) findViewById(R.id.btnHelp);
Button btnStart = (Button) findViewById(R.id.btnStart);
Button btnSettings = (Button) findViewById(R.id.btnSettings);
btnStart.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.this, GameActivity.class); //gets us to Game activity when Start Button is clicked
startActivity(i);
overridePendingTransition(R.animator.animation1, R.animator.animation2);
}
});
}
Game_Activity
ViewGroup kamilsLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
kamilsLayout = (ViewGroup) findViewById(R.id.kamilsLayout);
Button kamilsButton2 = (Button) findViewById(R.id.kamilsButton2);
kamilsButton2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
moveButton();
}
});
}
public void moveButton(){
View kamilsButton = findViewById(R.id.kamilsButton);
TransitionManager.beginDelayedTransition(kamilsLayout);
//Change size of the button
ViewGroup.LayoutParams sizeRules = kamilsButton.getLayoutParams();
sizeRules.height = 700;
kamilsButton.setLayoutParams(sizeRules);
}
Here is Logcat sorry for last lines but couldn't format it... :/
03-02 21:32:49.073 22427-22427/com.example.kamil.mychemicalreaction E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.kamil.mychemicalreaction, PID: 22427
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kamil.mychemicalreaction/com.example.kamil.mychemicalreaction.GameActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.kamil.mychemicalreaction.GameActivity.onCreate(GameActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)at android.app.ActivityThread.access$900(ActivityThread.java:161)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:126)at android.os.Handler.dispatchMessage(Handler.java:102)at android.os.Looper.loop(Looper.java:157)at android.app.ActivityThread.main(ActivityThread.java:5356)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:515)at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)at dalvik.system.NativeStart.main(Native Method)
XML
Game_Activity
<Button
android:layout_width="150dp"
android:layout_height="1dp"
android:id="#+id/kamilsButton"
android:gravity="bottom|fill_vertical"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#ff6aff01" />
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:text="Click"
android:id="#+id/kamilsButton2"
android:textSize="9dp"
android:clickable="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="102dp" />
Menu
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="My Chemical Reaction"
android:id="#+id/txtTitle"
android:textStyle="bold"
android:textColor="#ffa946ff"
android:textSize="30dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btnStart"
android:text="Start"
android:textColor="#ffffffff"
android:textSize="30sp"
android:layout_width="200dp"
android:layout_height="50dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:layout_marginBottom="61dp"
android:layout_above="#+id/btnSettings"
android:layout_alignLeft="#+id/btnSettings"
android:layout_alignStart="#+id/btnSettings" />
<Button
android:id="#+id/btnSettings"
android:text="Settings"
android:textColor="#ffffffff"
android:textSize="30sp"
android:layout_width="200dp"
android:layout_height="50dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:layout_above="#+id/btnHelp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="58dp" />
<Button
android:id="#+id/btnHelp"
android:text="Help"
android:textColor="#ffffffff"
android:textSize="30sp"
android:layout_width="200dp"
android:layout_height="50dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/btnSettings"
android:layout_alignStart="#+id/btnSettings"
android:layout_marginBottom="81dp" />
You're getting a NullPointerException when trying to reference your UI elements. From your XML, it appears you haven't given any layout an id of kamilsLayout. Try enclosing your UI elements in a layout with this ID.
Like Josef said. You're setting the same XML for two both activities, is that expected?
You're using setContentView(R.layout.activity_main). Maybe there is no ViewGroup on R.layout.activity_main layout. And you're trying to setting up that `
kamilsLayout = (ViewGroup) findViewById(R.id.kamilsLayout);
`

Application crashes on button click

Have problem that when I press button application crashes.
Crash text
package com.leftas.vidurkioskaiciavimas;
24367-24367/com.leftas.vidurkioskaiciavimas E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3704)
at android.view.View.performClick(View.java:4232)
at android.view.View$PerformClick.run(View.java:17298)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3699)
... 11 more
Caused by: java.lang.NullPointerException
at com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle.buttonEventHandler(vidurkioskaiciuokle.java:85)
... 14 more
I thinked that text is null because all time crashes on
"mUserOutput.setText(""); or "mUserInput.setText(mUserInput.getText() + "10");"
So I added
if (mUserOutput == null)
Log.e("output", null);
if (mUserInput == null)
Log.e("input", null);
But Nothing outputted...
So here is my main activity.
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
public class vidurkioskaiciuokle extends Activity {
int c;
TextView mUserOutput,mUserInput;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vidurkio_skaiciuokle);
TextView mUserOutput = (TextView) findViewById(R.id.textView2);
TextView mUserInput = (TextView) findViewById(R.id.textView);
if (mUserOutput == null)
Log.e("output", null);
if (mUserInput == null)
Log.e("input", null);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.vidurkioskaiciuokle, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.about:
startActivity(new Intent(this, About.class));
return true;
case R.id.exit:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void buttonEventHandler(View v) {
switch(v.getId()) {
case R.id.button1 :
mUserInput.setText(mUserInput.getText() + "1");
c = +1;
break;
case R.id.button2 :
mUserInput.setText(mUserInput.getText() + "2");
c = +2;
break;
case R.id.button3 :
mUserInput.setText(mUserInput.getText() + "3");
c = +3;
break;
case R.id.button4 :
mUserInput.setText(mUserInput.getText() + "4");
c = +4;
break;
case R.id.button5 :
mUserInput.setText(mUserInput.getText() + "5");
c = +5;
break;
case R.id.button6 :
mUserInput.setText(mUserInput.getText() + "6");
c = +6;
break;
case R.id.button7 :
mUserInput.setText(mUserInput.getText() + "7");
c = +7;
break;
case R.id.button8 :
mUserInput.setText(mUserInput.getText() + "8");
c = +8;
break;
case R.id.button9 :
mUserInput.setText(mUserInput.getText() + "9");
c = +9;
break;
case R.id.button10 :
mUserInput.setText(mUserInput.getText() + "10");
c = +10;
break;
case R.id.buttonclear :
mUserOutput.setText("");
mUserInput.setText("");
c = 0;
double average = 0;
break;
}
}
public void computeAverage(int [] scores)
{
double average = 0;
for (int c : scores) {
average += c;
}
average /= scores.length;
mUserOutput.setText(Double.toString(average));
}
Xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".vidurkioskaiciuokle">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="#+id/button1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="#+id/button2"
android:layout_alignTop="#+id/button1"
android:layout_toRightOf="#+id/button1"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="#+id/button3"
android:layout_alignBottom="#+id/button2"
android:layout_toRightOf="#+id/button2"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="#+id/button4"
android:layout_alignTop="#+id/button3"
android:layout_toRightOf="#+id/button3"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="#+id/button5"
android:layout_alignTop="#+id/button4"
android:layout_toRightOf="#+id/button4"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="#+id/button6"
android:layout_alignTop="#+id/button5"
android:layout_toRightOf="#+id/button5"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="#+id/button7"
android:layout_above="#+id/button2"
android:layout_toRightOf="#+id/button2"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="#+id/button8"
android:layout_alignTop="#+id/button9"
android:layout_toLeftOf="#+id/button9"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="#+id/button9"
android:onClick="buttonEventHandler"
android:layout_alignTop="#+id/button7"
android:layout_toRightOf="#+id/button1" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:id="#+id/button10"
android:layout_above="#+id/button4"
android:layout_toLeftOf="#+id/button5"
android:onClick="buttonEventHandler" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/button8"
android:layout_above="#+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView2"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_alignWithParentIfMissing="false"
android:layout_alignLeft="#+id/button8"
android:layout_alignRight="#+id/textView"
android:layout_above="#+id/button7" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:id="#+id/buttonclear"
android:onClick="buttonEventHandler"
android:layout_above="#+id/button5"
android:layout_toRightOf="#+id/button4"
android:layout_alignRight="#+id/textView2" />
I will be thankful if you could me help :)
If something need ask for it I will edit my question. :)
Thanks :)
Also If something wrong please say where and how to change it ;)
try this
mUserOutput = (TextView) findViewById(R.id.textView2);
mUserInput = (TextView) findViewById(R.id.textView);
You have already Declared textview's as class member. So initialize them as above.
This
TextView mUserOutput = (TextView) findViewById(R.id.textView2);
// makes mUserOutput local
findviewbyid and mUserOutput.setOnClickListener(this); required .
also implement onLCicklistener like:
public class MainActivity extends Activity implements OnClickListener{

java.lang.NoClassDefFoundError & java.lang.ClassNotFoundException - Android

my first question so I hope I'm doing this right.
I have added tablet layouts to my Android project and now I have a few crash reports on various devices. It works 100% just fine for me, however, testers with tablets get force closed at runtime.
The app is a simple dashboard allowing users to apply themes to third party launchers, Much like the Stark and Flatro icon packs.
Here's the errors:
java.lang.NoClassDefFoundError: com.arandompackage.jive.Fragment1$1
at com.arandompackage.jive.Fragment1.onActivityCreated(Fragment1.java:57)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1468)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:931)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1064)
at android.support.v4.view.ViewPager.populate(ViewPager.java:911)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1432)
at android.view.View.measure(View.java:12911)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:828)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:557)
at android.view.View.measure(View.java:12911)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4805)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:297)
at android.view.View.measure(View.java:12911)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:828)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:557)
at android.view.View.measure(View.java:12911)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4805)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:297)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2097)
at android.view.View.measure(View.java:12911)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
And
java.lang.RuntimeException: Unable to instantiate receiver com.arandompackage.jive.AnalogClockWidget: java.lang.ClassNotFoundException: com.arandompackage.jive.AnalogClockWidget
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2261)
at android.app.ActivityThread.access$1600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4946)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.arandompackage.jive.AnalogClockWidget
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2256)
... 10 more
I have done everything that all of these posts suggest, to no avail.
Here's the fragment1 java
package com.arandompackage.jive;
import com.arandompackage.jive.R;
import de.keyboardsurfer.android.widget.crouton.Crouton;
import de.keyboardsurfer.android.widget.crouton.Style;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
public class Fragment1 extends Fragment{
static final String ACTION_APPLY_ICON_THEME = "com.teslacoilsw.launcher.APPLY_ICON_THEME";
public static final String ACTION_MYTHEME = "com.gau.go.launcherex.MyThemes.mythemeaction";
public static final String ACTION_SET_THEME = "com.anddoes.launcher.SET_THEME";
static final String EXTRA_ICON_THEME_PACKAGE = "com.teslacoilsw.launcher.extra.ICON_THEME_PACKAGE";
static final String EXTRA_ICON_THEME_TYPE = "com.teslacoilsw.launcher.extra.ICON_THEME_TYPE";
public static final String EXTRA_PACKAGE_NAME = "com.anddoes.launcher.THEME_PACKAGE_NAME";
ImageButton button;
Button button2;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment_1, null);
}
private boolean isAppInstalled(String uri) {
PackageManager pm = getActivity().getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
#Override
public void onActivityCreated (Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
button = (ImageButton) getActivity().findViewById(R.id.apextheme);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (isAppInstalled("com.anddoes.launcher")) {
Intent intent3 = new Intent("com.anddoes.launcher.SET_THEME");
intent3.putExtra("com.anddoes.launcher.THEME_PACKAGE_NAME", getActivity().getPackageName());
startActivity(intent3);
Crouton.makeText(getActivity(), "TAP APPLY TO FINALIZE", Style.INFO, (ViewGroup) getView()).show();
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle(R.string.apexnotfound);
alert.setMessage(R.string.apexmarket);
alert.setIcon(R.drawable.apex_1);
alert.setPositiveButton((R.string.yes),
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("market://details?id=com.anddoes.launcher"));
startActivity(intent);
}
});
alert.setNegativeButton((R.string.no),
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
return;
}
});
alert.show();
}
}
});
And the xml for fragment_1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#f9f9f9"
android:paddingBottom="15dp" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" android:scrollbars="none"
android:overScrollMode="never">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<!-- Action -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="40dp" >
<ImageButton
android:id="#+id/actiontheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/alp_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/actiontheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/action"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/actiondetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<ImageButton
android:id="#+id/apextheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/apex_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/apextheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/apex"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/apexdetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_apex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<!-- Nova -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<ImageButton
android:id="#+id/novatheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/nova_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/novatheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/nova"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/novadetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_nova"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<!-- Adw -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:paddingTop="15dp" >
<ImageButton
android:id="#+id/adwextheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/adwex_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adwextheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/adwex"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/adwexdetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_adwex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<!-- go -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:paddingTop="15dp" >
<ImageButton
android:id="#+id/gotheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/go_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gotheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/go"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/godetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
EDIT: Here is the FragmentAdapter.java:
package com.arandompackage.jive;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.viewpagerindicator.IconPagerAdapter;
public class TestFragmentAdapter extends FragmentPagerAdapter implements IconPagerAdapter{
protected static final String[] CONTENT = new String[] {
"This", "Is", "A", "Test"
};
private int mCount = 4;
public TestFragmentAdapter(FragmentManager fm) {
super(fm);
}
#Override
public int getIconResId(int index) {
// TODO Auto-generated method stub
return 0;
}
#Override
public Fragment getItem(int position) {
Fragment fragment = new Fragment1();
switch(position){
case 0:
fragment = new Fragment1();
break;
case 1:
fragment = new Fragment2();
break;
case 2:
fragment = new Fragment3();
break;
case 3:
fragment = new Fragment4();
break;
}
return fragment;
}
#Override
public int getCount() {
return mCount;
}
#Override
public CharSequence getPageTitle(int position){
String title = "";
switch(position){
case 0:
title = "LAUNCHERS";
break;
case 1:
title = "EXTRAS";
break;
case 2:
title = "CONTACT";
break;
case 3:
title = "HELP";
break;
}
return title;
}
public void setCount(int count){
if (count > 0 && count < 10){
mCount = count;
notifyDataSetChanged();
}
}
}
And the TestFragment:
package com.arandompackage.jive;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
public class TestFragment extends Fragment{
private static final String KEY_CONTENT = "TestFragment:Content";
public static TestFragment newInstance(String content){
TestFragment fragment = new TestFragment();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 20; i++){
builder.append(content).append(" ");
}
builder.deleteCharAt(builder.length() -1);
fragment.mContent = builder.toString();
return fragment;
}
private String mContent = "???";
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)){
mContent = savedInstanceState.getString(KEY_CONTENT);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
TextView text = new TextView(getActivity());
text.setGravity(Gravity.CENTER);
text.setText(mContent);
text.setTextSize(20 * getResources().getDisplayMetrics().density);
text.setPadding(20, 20, 20, 20);
LinearLayout layout = new LinearLayout(getActivity());
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
layout.setGravity(Gravity.CENTER);
layout.addView(text);
return layout;
}
public void onSavedInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
outState.putString(KEY_CONTENT, mContent);
}
}
Here's the twist, the theme still gets applied to Apex Launcher....Any help is much appreciated in advance!
I can't remember my exact answer but this could well be to do with exporting of libraries. Go to project, properties, build path, order and export. The correct order is src, gen, android x.x.x, android private libraries, private libraries. Play around with checking/unchecking them.
I will update the answer when I get home
Edit:
My other SO answer can be found here:
Unfortunately Google Maps API Demos has stopped - Google Maps Android API v2

"unable to start activity component info" droid force close issue

Here's the java code for the class
package com.warriorsoft.mtgupanddown;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements View.OnClickListener {
int guy1;
int guy2;
MediaPlayer sound;
Button plus1g1, plus1g2, min1g1, min1g2, plus5g1, plus5g2, min5g1, min5g2,
GG, RESET;
TextView g1, g2;
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
super.onCreate(savedInstanceState);
guy1 = 20;
guy2 = 20;
min5g1 = (Button) findViewById(R.id.button1); // x
plus5g1 = (Button) findViewById(R.id.button2); //x
plus1g1 = (Button) findViewById(R.id.button3); // x
min1g1 = (Button) findViewById(R.id.button4); // x
min5g2 = (Button) findViewById(R.id.button5); // x
plus5g2 = (Button) findViewById(R.id.button6); //x
min1g2 = (Button) findViewById(R.id.button7); // x
plus1g2 = (Button) findViewById(R.id.button8); //x
RESET = (Button) findViewById(R.id.RESET);
GG = (Button) findViewById(R.id.GG);
g1 = (TextView) findViewById(R.id.tvPlayer1HP);
g2 = (TextView) findViewById(R.id.tvPlayer2HP);
min5g1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
guy1 -= 5;
g1.setText(guy1);
}
});
min5g2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
guy2 -= 5;
g2.setText(guy2);
}
});
min1g1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
guy1 -= 1;
g1.setText(guy1);
}
});
min1g2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
guy2 -= 1;
g2.setText(guy2);
}
});
plus5g2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
guy2 += 5;
g2.setText(guy2);
}
});
plus5g1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
guy1 += 5;
g1.setText(guy1);
}
});
plus1g1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
guy1 += 1;
g1.setText(guy1);
}
});
plus1g2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
guy2 += 1;
g2.setText(guy2);
}
});
RESET.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View arg0){
guy1 = 20;
guy2 = 20;
g2.setText(guy2);
g1.setText(guy1);
}
});
GG.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View arg0){
sound = MediaPlayer.create(MainActivity.this, R.raw.gg );
}
});
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
Here's the layout xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="#+id/tvPlayer2HP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="36dp"
android:text="20"
android:textSize="35dp" />
<TextView
android:id="#+id/tvPlayer1HP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="36dp"
android:text="20"
android:textSize="35dp" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_marginLeft="18dp"
android:layout_toRightOf="#+id/button1"
android:text="+5" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button3"
android:layout_alignBottom="#+id/button3"
android:layout_alignLeft="#+id/button2"
android:text="-1" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button2"
android:layout_alignRight="#+id/button1"
android:layout_marginBottom="28dp"
android:text="+1" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button5"
android:layout_alignBottom="#+id/button5"
android:layout_alignParentRight="true"
android:text="+5" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignBottom="#+id/button2"
android:layout_marginRight="14dp"
android:layout_toLeftOf="#+id/button6"
android:text="-5" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/button5"
android:layout_alignTop="#+id/button4"
android:text="+1" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button7"
android:layout_alignBottom="#+id/button7"
android:layout_toRightOf="#+id/button5"
android:text="-1" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText1"
android:layout_alignLeft="#+id/button5"
android:ems="10"
android:hint="Guy 1" >
</EditText>
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/button2"
android:layout_below="#+id/button1"
android:layout_marginTop="36dp"
android:ems="10"
android:hint="Guy 2" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvPlayer1HP"
android:layout_marginTop="74dp"
android:text="-5" />
<ImageView
android:id="#+id/GG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvPlayer2HP"
android:layout_centerHorizontal="true"
android:minHeight="140dp"
android:minWidth="120dp"
android:src="#drawable/gg" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="14dp"
android:text="Optimal sideways"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/RESET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="RESET" />
</RelativeLayout>
And here's the logcat
01-16 14:01:51.292: W/dalvikvm(699): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-16 14:01:51.302: E/AndroidRuntime(699): FATAL EXCEPTION: main
01-16 14:01:51.302: E/AndroidRuntime(699): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.warriorsoft.mtgupanddown/com.warriorsoft.mtgupanddown.MainActivity}: java.lang.ClassCastException: android.widget.ImageView
01-16 14:01:51.302: E/AndroidRuntime(699): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-16 14:01:51.302: E/AndroidRuntime(699): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-16 14:01:51.302: E/AndroidRuntime(699): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-16 14:01:51.302: E/AndroidRuntime(699): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-16 14:01:51.302: E/AndroidRuntime(699): at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 14:01:51.302: E/AndroidRuntime(699): at android.os.Looper.loop(Looper.java:123)
01-16 14:01:51.302: E/AndroidRuntime(699): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-16 14:01:51.302: E/AndroidRuntime(699): at java.lang.reflect.Method.invokeNative(Native Method)
01-16 14:01:51.302: E/AndroidRuntime(699): at java.lang.reflect.Method.invoke(Method.java:507)
01-16 14:01:51.302: E/AndroidRuntime(699): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-16 14:01:51.302: E/AndroidRuntime(699): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-16 14:01:51.302: E/AndroidRuntime(699): at dalvik.system.NativeStart.main(Native Method)
01-16 14:01:51.302: E/AndroidRuntime(699): Caused by: java.lang.ClassCastException: android.widget.ImageView
01-16 14:01:51.302: E/AndroidRuntime(699): at com.warriorsoft.mtgupanddown.MainActivity.onCreate(MainActivity.java:33)
01-16 14:01:51.302: E/AndroidRuntime(699): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-16 14:01:51.302: E/AndroidRuntime(699): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-16 14:01:51.302: E/AndroidRuntime(699): ... 11 more
01-16 14:01:53.712: I/Process(699): Sending signal. PID: 699 SIG: 9
The problem is running the code on a phone.
It tells me that the program broke in some unexpected way and forces me to force close.
If anyone could please help me understand what i've done wrong i'll be eternally grateful
I am still new to programming and can barely understand the logcats
please go easy
Thankyou for trying
You are finding the ImageView and casting it to Button.
check this line of code.
GG = (Button) findViewById(R.id.GG);
Change the type of GG as ImageView and typecast to ImageView as below:
ImageView GG;
GG = (ImageView) findViewById(R.id.GG);
Change this to this
GG = (Button) findViewById(R.id.GG);
to
GG = (ImageView) findViewById(R.id.GG);
you cannot cast an ImageView to a Button. Which is what you are doing

Categories

Resources