android cannot be resolved or is not a field error - java

I created a tictactoe android game, and when i try to link the strings.xml file to activity.java I receive an error.
Here is my activity.java
package com.tictactoeoyna.www;
import android.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TicTacToeOynaActivity extends Activity {
private TicTacToeOyun mGame;
private Button mBoardButtons[];
private TextView mInfoTextView;
private TextView mHumanCount;
private TextView mTieCount;
private TextView mAndroidCount;
private int mHumanCounter = 0;
private int mTieCounter = 0;
private int mAndroidCounter = 0;
private boolean mHumanFirst = true;
private boolean mGameOver = false;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBoardButtons = new Button[TicTacToeOyun.getBOARD_SIZE()];
mBoardButtons[0] = (Button) findViewById(R.id.one);// it should be blue but not
mBoardButtons[1] = (Button) findViewById(R.id.two);//same
mBoardButtons[2] = (Button) findViewById(R.id.three);
mBoardButtons[3] = (Button) findViewById(R.id.four);
mBoardButtons[4] = (Button) findViewById(R.id.five);
mBoardButtons[5] = (Button) findViewById(R.id.six);
mBoardButtons[6] = (Button) findViewById(R.id.seven);
mBoardButtons[7] = (Button) findViewById(R.id.eight);
mBoardButtons[8] = (Button) findViewById(R.id.nine);//until here
mInfoTextView = (TextView) findViewById(R.id.information);
mHumanCount = (TextView) findViewById(R.id.humanCount);
mTieCount = (TextView) findViewById(R.id.tiesCount);
mAndroidCount = (TextView) findViewById(R.id.androidCount);
mHumanCount.setText(Integer.toString(mHumanCounter));
mTieCount.setText(Integer.toString(mTieCounter));
mAndroidCount.setText(Integer.toString(mAndroidCounter));
mGame = new TicTacToeOyun();
startNewGame();
}
private void startNewGame()
{
mGame.clearBoard();
for (int i = 0; i < mBoardButtons.length; i++)
{
mBoardButtons[i].setText("");
mBoardButtons[i].setEnabled(true);
mBoardButtons[i].setOnClickListener(new ButtonClickListener(i));
}
if (mHumanFirst)
{
mInfoTextView.setText(R.string.first_human);
mHumanFirst = false;
}
else
{
mInfoTextView.setText(R.string.turn_computer);
int move = mGame.getComputerMove();
setMove(mGame.ANDROID_PLAYER, move);
mHumanFirst = true;
}
}
private class ButtonClickListener implements View.OnClickListener
{
int location;
public ButtonClickListener(int location)
{
this.location = location;
}
public void onClick(View view)
{
if (!mGameOver)
{
if (mBoardButtons[location].isEnabled())
{
setMove(mGame.HUMAN_PLAYER, location);
int winner = mGame.checkForWinner();
if (winner == 0)
{
mInfoTextView.setText(R.string.turn_computer);
int move = mGame.getComputerMove();
setMove(mGame.ANDROID_PLAYER, move);
winner = mGame.checkForWinner();
}
if (winner == 0)
mInfoTextView.setText(R.string.turn_human);
else if (winner == 1)
{
mInfoTextView.setText(R.string.result_tie);
mTieCounter++;
mTieCount.setText(Integer.toString(mTieCounter));
mGameOver = true;
}
else if (winner == 2)
{
mInfoTextView.setText(R.string.result_human_wins);
mHumanCounter++;
mHumanCount.setText(Integer.toString(mHumanCounter));
mGameOver = true;
}
else
{
mInfoTextView.setText(R.string.result_android_wins);
mAndroidCounter++;
mAndroidCount.setText(Integer.toString(mAndroidCounter));
mGameOver = true;
}
}
}
}
}
private void setMove(char player, int location)
{
mGame.setMove(player, location);
mBoardButtons[location].setEnabled(false);
mBoardButtons[location].setText(String.valueOf(player));
if (player == mGame.HUMAN_PLAYER)
mBoardButtons[location].setTextColor(Color.GREEN);
else
mBoardButtons[location].setTextColor(Color.RED);
}
}
The error is on one, two, three...nine and information count, human count etc. Here is my fragment file, so why can't I see one, two, three....nine labeled blue? Why is it not recognized? What have I done wrong ? I received the errors after findviewbyid.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/playArea"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="one"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/one"
android:textSize="70dp" />
<Button
android:id="#+id/two"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/two"
android:textSize="70dp" />
<Button
android:id="#+id/three"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/three"
android:textSize="70dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="#+id/four"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/four"
android:textSize="70dp" />
<Button
android:id="#+id/five"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/five"
android:textSize="70dp" />
<Button
android:id="#+id/six"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/six"
android:textSize="70dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="#+id/seven"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/seven"
android:textSize="70dp" />
<Button
android:id="#+id/eight"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/eight"
android:textSize="70dp" />
<Button
android:id="#+id/nine"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/nine"
android:textSize="70dp" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/information"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:text="#string/info"
android:textSize="25dp" />
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/human"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/human" />
<TextView
android:id="#+id/humanCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp" />
<TextView
android:id="#+id/ties"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ties" />
<TextView
android:id="#+id/tiesCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp" />
<TextView
android:id="#+id/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/android" />
<TextView
android:id="#+id/androidCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
</LinearLayout>

import com.tictactoeoyna.www.R;
and removeimport android.R;

When you got this type of error at anywhere and you have import android.R; then just remove import android.R;.

Related

ScrollView not scrolling with onTouch

My scroll view isn't scrolling. I have a feeling it may be due to an "onTouch" method I have that instead of scrolling is incrementing the counter shown. I have tried to find some solutions but none seem to be directly related to mine and any attempt to change the scroll view has not worked.
I am not sure how to get around this and any help would be greatly appreciated.
Java Code
package com.alanlyne.tbm.Variables.varL;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.alanlyne.tbm.Menu.Menu;
import com.alanlyne.tbm.Menu.menuCounter;
import com.alanlyne.tbm.R;
import com.alanlyne.tbm.Variables.Var;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class varL2 extends AppCompatActivity {
TextView t0, t1, t2, t3, t4, t5, t6, t7, t8, x;
Button b1;
int counter = 0;
DatabaseReference databaseName;
private long mLastClickTime = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_var_l2);
databaseName = FirebaseDatabase.getInstance().getReference("counter");
t0 = findViewById(R.id.t0);
t1 = findViewById(R.id.t1);
t2 = findViewById(R.id.t2);
t3 = findViewById(R.id.t3);
t4 = findViewById(R.id.t4);
t5 = findViewById(R.id.t5);
t6 = findViewById(R.id.t6);
t7 = findViewById(R.id.t7);
t8 = findViewById(R.id.t8);
b1 = findViewById(R.id.b1);
x = findViewById(R.id.x);
x.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent x = new Intent(varL2.this, Var.class);
startActivity(x);
}
});
View view = findViewById(R.id.ScrollView01);
view.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent event) {
if (SystemClock.elapsedRealtime() - mLastClickTime < 500) {
System.out.println("Fun");
}
else{
mLastClickTime = SystemClock.elapsedRealtime();
counter++;
System.out.println(counter);
if (counter > 0) {
TextView tv = findViewById(R.id.t1);
tv.setVisibility(View.VISIBLE);
}
if (counter > 1) {
TextView tv = findViewById(R.id.t2);
tv.setVisibility(View.VISIBLE);
}
if (counter > 2) {
TextView tv = findViewById(R.id.t3);
tv.setVisibility(View.VISIBLE);
}
if (counter > 3) {
TextView tv = findViewById(R.id.t4);
tv.setVisibility(View.VISIBLE);
}
if (counter > 4) {
TextView tv = findViewById(R.id.t5);
tv.setVisibility(View.VISIBLE);
}
if (counter > 5) {
TextView tv = findViewById(R.id.t6);
tv.setVisibility(View.VISIBLE);
}
if (counter > 6) {
TextView tv = findViewById(R.id.t7);
tv.setVisibility(View.VISIBLE);
}
if (counter > 7) {
TextView tv = findViewById(R.id.t8);
tv.setVisibility(View.VISIBLE);
}
if (counter > 8) {
Button b1 = findViewById(R.id.b1);
b1.setVisibility(View.VISIBLE);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent Menu = new Intent(varL2.this, Var.class);
startActivity(Menu);
addCounter();
}
});
}}
return true;
}
});
}
private void addCounter(){
if(Menu.counter == 12) {
Menu.counter = 13;
menuCounter counter = new menuCounter(Menu.counter);
databaseName.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(counter);
System.out.println("AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");
}
}
}
XML Code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bgcolour"
tools:context=".Variables.varL.varL2">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="#+id/t0"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="#drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="There are 8 primitive data types for creating variables in Java."
android:textColor="#android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/t1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/t1"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="byte\n8 bit integer\n-128 to 127\nDefault of 0"
android:textColor="#android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/t2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/t0" />
<TextView
android:id="#+id/t2"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="short\n16 bit integer\n-32768 to 32767\nDefault of 0"
android:textColor="#android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/t3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/t1" />
<TextView
android:id="#+id/t3"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="int\n32 bit integer\n-2147483648 to 2147483647\nDefault of 0"
android:textColor="#android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/t2" />
<TextView
android:id="#+id/t4"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="long\n64 bit integer\n-9223372036854775808 to 9223372036854775807\nDefault of 0L"
android:textColor="#android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/t5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/t3" />
<TextView
android:id="#+id/t5"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="float\nDecimal point number\n1.5*10^-45 to 3.4*10^38\nDefault of 0.0f"
android:textColor="#android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/t6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/t4" />
<TextView
android:id="#+id/t6"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="double\nDecimal point number\n5.0*10^-324 to 1.7*10^308\nDefault of 0.0"
android:textColor="#android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/t7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/t5" />
<TextView
android:id="#+id/t7"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="char\nA unicode character e.g 'a','b'\n(\u0000 to \uffff) or (0 to 65535)\nDefault of null"
android:textColor="#android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/t8"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/t6" />
<TextView
android:id="#+id/t8"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="boolean\nLogical true or false\ntrue or false\nDefault of false"
android:textColor="#android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/b1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/t7" />
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="150dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="20dp"
android:background="#drawable/b_round"
android:text="Continue"
android:textColor="#android:color/white"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/t8" />
<TextView
android:id="#+id/x"
android:layout_width="15dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:text="x"
android:textColor="#android:color/white"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="#+id/t0"
app:layout_constraintEnd_toEndOf="#+id/t0"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Fixed the issue by having the
View view = findViewById(R.id.ScrollView01);
reference the id of the constraint layout instead of the scroll view.
Usually when you are dealing with ScrollView you need to set android:fillViewport to true
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

Android studio, android scrolling down and up enable

I want to add something like scrolling from top to bottom and vice versa but i don't know how to add this function, i was trying with ScrollView but that gave nothing.
MainActivity.java :
package com.example.marek.przelicznikpaliw;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private EditText a1;
private EditText b1;
private EditText c1;
private EditText d1;
private TextView tv;
private TextView tv2;
private TextView tv3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//pola
a1 = (EditText) findViewById(R.id.cel);
b1 = (EditText) findViewById(R.id.pali);
c1 = (EditText) findViewById(R.id.litr);
d1 = (EditText) findViewById(R.id.koszt);
// wynik
tv = (TextView) findViewById(R.id.wynikKoszt);
tv2 = (TextView) findViewById(R.id.wynikKilometry);
tv3 = (TextView) findViewById(R.id.wynikKosztx2);
findViewById(R.id.button).setOnClickListener(onClickListener);
findViewById(R.id.button2).setOnClickListener(onClickListener);
}
private View.OnClickListener onClickListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
float a = 0;
float b = 0;
float c = 0;
float d = 0;
float wynik = 0;
float wynik2 = 0;
float wynik3 = 0;
try {
a = Float.parseFloat(a1.getText().toString());
b = Float.parseFloat(b1.getText().toString());
c = Float.parseFloat(c1.getText().toString());
d = Float.parseFloat(d1.getText().toString());
} catch (Exception e) {
e.printStackTrace();
}
if (view.getId() == R.id.button) {
wynik = ((b / 100) * a) * c;
tv.setText(String.valueOf(wynik));
wynik2 = (((b / 100) * a) * c)*2;
tv3.setText(String.valueOf(wynik2));
} else if (view.getId() == R.id.button2) {
wynik3 = d / ((b * c) / 100);
tv2.setText(String.valueOf(wynik3));
}
}
};
}
activity_main.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: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=".MainActivity"
android:orientation="vertical"
android:onClick="onButtonClick"
android:weightSum="1">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cel"
android:hint="Ilosc km do celu to:"
android:layout_centerHorizontal="true"
android:numeric="integer|decimal" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pali"
android:hint="Ile litrow pali na 100km"
android:layout_centerHorizontal="true"
android:layout_below="#+id/cel"
android:numeric="integer|decimal" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/litr"
android:hint="Cena za litr"
android:layout_below="#+id/pali"
android:layout_centerHorizontal="true"
android:numeric="integer|decimal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:layout_below="#+id/litr"
android:layout_centerHorizontal="true"
android:hint="Licz zlotowki"
android:text="Licz koszty"
android:clickable="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/koszt"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:hint="Za ile zl zostalo zatankowane gaz/paliwo?"
android:numeric="integer|decimal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Licz kilometry"
android:id="#+id/button2"
android:layout_below="#+id/koszt"
android:layout_centerHorizontal="true"
android:clickable="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Dojedziesz w wybrany cel za(zł):"
android:id="#+id/textView" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/emptystring"
android:id="#+id/wynikKoszt"
android:textIsSelectable="false" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Oraz spowrotem za(zł):"
android:id="#+id/textView2" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/emptystring"
android:id="#+id/wynikKosztx2"
android:layout_weight="0.06" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Za tę kwotę przejedziesz(km):"
android:id="#+id/textView3" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/emptystring"
android:id="#+id/wynikKilometry" />

What is the best way to delete the last digit in a calculator app

package com.gamesup.braingame;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Easy extends Activity {
EditText display;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.easy);
display = (EditText)findViewById(R.id.displayText);
display.setText("?");
}
static boolean isEmpty = true;
public void num_Clicked(View v){
Button btn = (Button) findViewById(v.getId());
//getting the button object and using a view to get the id of the buttons
if(isEmpty){
display.setText(btn.getText());
isEmpty = false;
}
else{
display.append(btn.getText().toString());
}
if (v.getId()== R.id.del_button){
String s = display.getText().toString();
s = s.substring(0, s.length() - 1);
display.setText(s);
}
}
}
This is my code for the digits to be displayed on a calculator android app. What would i have to use to delete the last digit displayed? Also would i do this inside the num_Clicked function, like this:
if (v.getId()== R.id.del_button) {
}
This is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/number1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/number_1_label" />
<Button
android:id="#+id/number2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/number_2_label" />
<Button
android:id="#+id/number3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/number_3_label" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/number4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/number_4_label" />
<Button
android:id="#+id/number5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/number_5_label" />
<Button
android:id="#+id/number6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/number_6_label" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/number7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/number_7_label" />
<Button
android:id="#+id/number8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/number_8_label" />
<Button
android:id="#+id/number9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/number_9_label" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/del_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/delete_label" />
<Button
android:id="#+id/number0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/number_0_label" />
<Button
android:id="#+id/hash_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/hash_label" />
<Button
android:id="#+id/minus_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="num_Clicked"
android:text="#string/minus_label" />
</TableRow>
</TableLayout>
<EditText
android:id="#+id/displayText"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_above="#+id/tableLayout1"
android:layout_alignLeft="#+id/tableLayout1"
android:layout_alignRight="#+id/tableLayout1"
android:ems="10"
android:inputType="number" />
</RelativeLayout>
You can remove the last character in a string by using the substring method.
In the method where the delete press is being captured:
String s = display.getText().toString();
s = s.substring(0, s.length() - 1);
display.setText(s);
This will replace the string s with the last character removed
The full code to do this would be:
package com.gamesup.braingame;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Easy extends Activity {
EditText display;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.easy);
display = (EditText)findViewById(R.id.displayText);
display.setText("?");
}
static boolean isEmpty = true;
public void num_Clicked(View v){
Button btn = (Button) v;
if (v.getId()== R.id.del_button){
String s = display.getText().toString();
s = s.substring(0, s.length() - 1);
display.setText(s);
return;
}
if(isEmpty){
display.setText(btn.getText());
isEmpty = false;
}
else{
display.append(btn.getText().toString());
}
}
}

How do you pass data from FragmentA to hostActivity then update fragmentB

I have three fragments, Player1Tun, Player2Turn and TicTacToeLayout. Player1Turn and Player2Turn are inner-switching every time a player makes a move and TicTacToeLayout contains the tic tac toe table which update everytime the fragments switches. What I'm trying to do is to send the data from either player fragments to the host activity (while the program is still running) and then from there, I'll update the table in the TicTacToeLayout. Any ideas or method I can do it?
Player1:
package As2.packageTK;
//import android.app.Activity;
import java.util.ArrayList;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class PlayerTurn2 extends Fragment{
TextView p2Name;
TextView p2Icon;
Button doneP2;
Button resetP2;
EditText row;
EditText column;
TicTacToeLayout myObject2 = new TicTacToeLayout();
ArrayList<String> player2;
Bundle extras = new Bundle();
int turn = 2;
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.playerturn2, container, false);
return view;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
extras = getArguments();
player2 = new ArrayList<String>(extras.getStringArrayList("player2"));
//Toast.makeText(getActivity(), player2.get(0), Toast.LENGTH_LONG).show();
//Toast.makeText(getActivity(), player2.get(1), Toast.LENGTH_LONG).show();
p2Name = (TextView) getActivity().findViewById(R.id.p2NameInfo);
p2Icon = (TextView) getActivity().findViewById(R.id.p2IconInfo);
row = (EditText) getActivity().findViewById(R.id.rowP2);
column = (EditText) getActivity().findViewById(R.id.columnP2);
doneP2 = (Button) getActivity().findViewById(R.id.doneP2);
//resetP2 = (Button) getActivity().findViewById(R.id.resetP2);
setPlayer(); //sets all the information of player 2, name, icon, image, etc
doneP2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
callPlayer1Fragment(); //switches with first player
}
});
}
public void callPlayer1Fragment()
{
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment Player1Frag = new PlayerTurn1();
Player1Frag.setArguments(extras);
ft.replace(R.id.fragment_container, Player1Frag);
ft.commit();
}
public boolean checkField()
{
if(row == null || column == null)
{
Toast.makeText(getActivity(), "Please input the row or column!", Toast.LENGTH_LONG).show();
return false;
}
else
return true;
}
public void setPlayer()
{
String name = player2.get(0);
if(!name.equals(""))
p2Name.setText("Player Name: " + name);
else
p2Name.setText("");
String icon = player2.get(1);
if(!icon.equals(""))
p2Icon.setText("Player Icon: " + icon);
else
p2Icon.setText("");
}
}
player 2 fragment is exactly the same code so I won't bother adding it.
TicTacToeLayout fragment class:
public class TicTacToeLayout extends Fragment {
TextView image1, image2, image3, image4, image5, image6, image7, image8, image9;
TextView[][] images;
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.tictactoe_layout, container, false);
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
image1 = (TextView) getActivity().findViewById(R.id.Image1);
image2 = (TextView) getActivity().findViewById(R.id.Image2);
image3 = (TextView) getActivity().findViewById(R.id.Image3);
image4 = (TextView) getActivity().findViewById(R.id.Image4);
image5 = (TextView) getActivity().findViewById(R.id.Image5);
image6 = (TextView) getActivity().findViewById(R.id.Image6);
image7 = (TextView) getActivity().findViewById(R.id.Image7);
image8 = (TextView) getActivity().findViewById(R.id.Image8);
image9 = (TextView) getActivity().findViewById(R.id.Image9);
images = new TextView[][]{ {image1, image2, image3},
{image4, image5, image6},
{image7, image8, image9} };
toast();
}
public void toast()
{
Toast.makeText(getActivity(), images[0][0].getText().toString(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), images[0][1].getText().toString(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), images[0][2].getText().toString(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), images[1][0].getText().toString(), Toast.LENGTH_LONG).show();
}
public void play(int row, int column, String icon)
{
images[row-1][column-1].setText(icon);
}
}
here's the XML layout for playerturn2
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/tablerow0"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/player2Num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="100dp"
android:gravity="center_horizontal"
android:text="Player 2"
android:textSize="20dp" />
</TableRow>
<TableRow
android:id="#+id/tablerow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/p2NameInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player Name: "
android:textSize="20dp" />
</TableRow>
<TableRow
android:id="#+id/tablerow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/p2IconInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player icon: "
android:textSize="20dp" />
</TableRow>
<TableRow
android:id="#+id/tablerow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/p2PicInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player picture:"
android:textSize="20dp" />
</TableRow>
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#android:drawable/editbox_background" />
<TableRow
android:id="#+id/rowNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="50dp"
android:gravity="center_horizontal"
android:text="Row (1-3):"
android:textSize="20dp" />
<EditText
android:id="#+id/rowP2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:width="50dp" />
</TableRow>
<TableRow
android:id="#+id/colNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="50dp"
android:gravity="center_horizontal"
android:text="Col (1-3):"
android:textSize="20dp" />
<EditText
android:id="#+id/columnP2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:width="50dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp" >
<Button
android:id="#+id/doneP2"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="Done"
/>
<Button
android:id="#+id/resetP2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
/>
</TableRow>
</TableLayout>
here's the layout for tictactoelayout.xml
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tictactoe"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" >
<TextView
android:id="#+id/Image1"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="1"
android:textSize="70dp" />
<TextView
android:id="#+id/Image2"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="2"
android:textSize="70dp" />
<TextView
android:id="#+id/Image3"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="3"
android:textSize="70dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/Image4"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="4"
android:textSize="70dp" />
<TextView
android:id="#+id/Image5"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="5"
android:textSize="70dp" />
<TextView
android:id="#+id/Image6"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="6"
android:textSize="70dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/Image7"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="7"
android:textSize="70dp" />
<TextView
android:id="#+id/Image8"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="8"
android:textSize="70dp" />
<TextView
android:id="#+id/Image9"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="9"
android:textSize="70dp" />
</TableRow>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="#+id/win"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Winner"
android:textSize="20dp" />
<EditText
android:id="#+id/winner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:ems="10" />
</RelativeLayout>
</TableLayout>
and finally the host activity's xml layout: tictactoegame.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/frag2"
android:name="As2.packageTK.TicTacToeLayout"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
My friend did the same but with a implementing an interface he created in the fragments and having the main activity implement the interface. With that, he used a method to pass datas. Maybe it's not clear but if you know what I'm trying to say then you could clear it out for all of us :)
your friend is right, communicating with other fragments is nicely explained in the docs:
http://developer.android.com/training/basics/fragments/communicating.html

NullPointerException in Android Program in onCreate()

I am fairly new to android and am writing an app that will solve physics problems. The math is going well thanks to some help from these forums, but when I try to start my activity from a list it comes up with a nullpointerexception in the onCreate Method of the new activity. This doesn't seem to make much sense though, because all thats there is a submit button that executes the math from some EditText views. Here is my code.
package android.physicsengine;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import java.lang.Math;
public class ProjectileMotion extends Activity {
private EditText acceleration;
private EditText finalVelocity;
private EditText initialVelocity;
private EditText time;
private EditText deltay;
private EditText velocity;
private EditText deltax;
private Button submitButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.projectile_motion_layout);
submitButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
acceleration = (EditText)findViewById(R.id.acceleration);
double a = Doublify(acceleration);
finalVelocity = (EditText)findViewById(R.id.finalVelocity);
double vf = Doublify(finalVelocity);
initialVelocity = (EditText)findViewById(R.id.intitialVelocity);
double vi = Doublify(initialVelocity);
time = (EditText)findViewById(R.id.time);
double t = Doublify(time);
deltay = (EditText)findViewById(R.id.deltay);
double y = Doublify(deltay);
velocity = (EditText)findViewById(R.id.velocity);
double vx = Doublify(velocity);
deltax = (EditText)findViewById(R.id.deltax);
double x = Doublify(deltax);
//Y Axis
if(time.getText()==null && deltay.getText()==null){
time.setText(Double.toString((vf-vi)/a));
deltay.setText(Double.toString(((vf-vi)/a)+(a*Math.pow(((vf-vi)/a),2))));
}
if(acceleration.getText()==null && deltay.getText()==null){
acceleration.setText(Double.toString((vf-vi)/t));
deltay.setText(Double.toString((vi*t+.5*((vf-vi)/t))*Math.pow(t,2)));
}
if(acceleration.getText()==null && time.getText()==null){
acceleration.setText(Double.toString(((Math.pow(vf,2)-Math.pow(vi,2)))/2*y));
time.setText(Double.toString(2*y*(vf-vi)/(Math.pow(vf,2)-vi)));
}
if(initialVelocity.getText()==null && deltay.getText()==null){
initialVelocity.setText(Double.toString(vf-a*t));
deltay.setText(Double.toString((vf-a*t)*t+.5*a*Math.pow(t,2)));
}
if(initialVelocity.getText()==null && time.getText()==null){
initialVelocity.setText(Double.toString(Math.sqrt(Math.pow(vf,2)-2*a*y)));
time.setText(Double.toString((vf-Math.sqrt(Math.pow(vf,2)-2*a*y))/2));
}
if(initialVelocity.getText()==null && acceleration.getText()==null){
initialVelocity.setText(Double.toString(vf-2*(vf-y/t)));
acceleration.setText(Double.toString((2/t)*(vf-y/t)));
}
if(finalVelocity.getText()==null && deltay.getText()==null){
finalVelocity.setText(Double.toString(vi+a*t));
deltay.setText(Double.toString(vi*t+.5*a*Math.pow(t,2)));
}
if(finalVelocity.getText()==null && time.getText()==null){
finalVelocity.setText(Double.toString(Math.sqrt(Math.pow(vi,2)+2*a*y)));
time.setText(Double.toString(((Math.sqrt(Math.pow(vi,2)+2*a*y)-vi))/a));
}
if(finalVelocity.getText()==null && acceleration.getText()==null){
acceleration.setText(Double.toString(2*(y-vi*t)/Math.pow(t,2)));
finalVelocity.setText(Double.toString(vi+(2*(y-vi*t)/t)));
}
if(finalVelocity.getText()==null && initialVelocity.getText()==null){
initialVelocity.setText(Double.toString((y-.5*a*Math.pow(t,2))/t));
finalVelocity.setText(Double.toString((y-.5*a*Math.pow(t,2))/t)+a*t);
}
}
});
}
private double Doublify(EditText editText){
if(editText.getText()!= null){
return Double.parseDouble(editText.getText().toString());
}
return 0;
}
}
and the XML
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableRow>
<TextView android:text="Projectile Motion Engine"
android:textSize="25dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="4"
android:layout_gravity="center" />
</TableRow>
<TableRow>
<TextView android:text="X axis"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2"
android:textStyle="bold"/>
<TextView android:text="Y axis"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2"
android:textStyle="bold"/>
</TableRow>
<TableRow>
<TextView android:text="accel(m/s^2)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/acceleration"
android:text="9.8"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:text="deltax(m)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/deltax"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView android:text="init v(m/s)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/intitialVelocity"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:text="v ="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/velocity"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView android:text="final v(m/s)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/finalVelocity"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:text="time(s)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/time"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView android:text="deltay(m)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/deltay"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button android:id="#+id/submitButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="Launch" />
</TableRow>
</TableLayout>
super.onCreate(savedInstanceState);
setContentView(R.layout.projectile_motion_layout);
submitButton.setOnClickListener(new OnClickListener() {
You forgot to assign your submitButton (with findViewById)
super.onCreate(savedInstanceState);
setContentView(R.layout.projectile_motion_layout);
submitButton = (Button) findViewById((R.id.submitButton); // new line
submitButton.setOnClickListener(new OnClickListener() {
Based on the code you've posted, it appears that you call
submitButton.setOnClickListener(new OnClickListener() {
before instantiating submitButton with a value. This would cause a NullPointer
projectile_motion_layout may not be in your android manifest. I would check that first.
You can find the Application Nodes under the Application tab in the manifest.

Categories