Does any one know how to fix this error, THANK YOU!!
I think something wrong with "public void choose answer" in MainActivity, because then i try press on 1 of 4 buttons I get this error and app crash.
Error message:
FATAL EXCEPTION: main
Process: com.example.braintrainer, PID: 19387
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at com.example.braintrainer.MainActivity.chooseAnswer(MainActivity.java:24)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Here all buttons have same onClick (maybe here something wrong?)- android:onClick="chooseAnswer"
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">
<Button
android:id="#+id/startButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#4CAF50"
android:onClick="start"
android:text="Go!"
android:textSize="60sp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#4CAF50"
android:text="30s"
android:textAlignment="center"
android:textSize="25sp" />
<TextView
android:id="#+id/sumTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="31 + 12"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="25sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#03A9F4"
android:text="0/0"
android:textAlignment="center"
android:textSize="25sp" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/gridLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="#+id/resultTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="300dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout"
app:layout_constraintWidth_max="300dp">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<Button
android:id="#+id/button0"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#9C27B0"
android:onClick="chooseAnswer"
android:text="3"
android:textSize="36sp"
app:layout_constraintBottom_toTopOf="#+id/guideline2"
app:layout_constraintEnd_toStartOf="#+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#CDDC39"
android:onClick="chooseAnswer"
android:text="3"
android:textSize="36sp"
app:layout_constraintBottom_toTopOf="#+id/guideline2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#FF5722"
android:onClick="chooseAnswer"
android:text="3"
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline2" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#4CAF50"
android:onClick="chooseAnswer"
android:text="3"
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline"
app:layout_constraintTop_toBottomOf="#+id/guideline2" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="#+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Correct!"
android:textSize="40sp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/startButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here Im trying call buttons from "public void chooseAnswer(View view)" to check if they are working and Im getting their id
MainActivity.java
package com.example.braintrainer;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
Button startButton;
TextView resultTextView;
ArrayList<Integer> answers = new ArrayList<Integer>();
int locationOfCorrectAnswer;
int score = 0;
public void chooseAnswer(View view){
if (view.getTag().toString().equals(Integer.toString(locationOfCorrectAnswer))){
Log.i("TAG", String.valueOf(view.getTag()));
}
}
public void start(View view){
startButton.setVisibility(View.INVISIBLE);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startButton=(Button)findViewById(R.id.startButton);
TextView sumTextView = (TextView)findViewById(R.id.sumTextView);
Button button0 = (Button)findViewById(R.id.button0);
Button button1 = (Button)findViewById(R.id.button1);
Button button2 = (Button)findViewById(R.id.button2);
Button button3 = (Button)findViewById(R.id.button3);
resultTextView = (TextView)findViewById(R.id.resultTextView);
Random rand = new Random();
int a = rand.nextInt(21);
int b = rand.nextInt(21);
sumTextView.setText(Integer.toString(a) + " + " + Integer.toString(b));
locationOfCorrectAnswer = rand.nextInt(4);
int incorrectAnswer;
for (int i=0; i<4; i++){
if (i == locationOfCorrectAnswer){
answers.add(a + b);
} else {
incorrectAnswer = rand.nextInt(41);
while (incorrectAnswer == a + b){
incorrectAnswer = rand.nextInt(41);
}
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)));
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.braintrainer">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You try to check buttons by tag but you didn't set any tags in xml
It's a NullPointerException caused by this. Please check
if (view.getTag().toString().equals(Integer.toString(locationOfCorrectAnswer))){
Log.i("TAG", String.valueOf(view.getTag()));
}
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
as view.getTag() return null.
try to set the tag to your Buttons like this:
<Button
android:id="#+id/button0"
android:tag="1" // this line
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#9C27B0"
android:onClick="chooseAnswer"
android:text="3"
android:textSize="36sp"
app:layout_constraintBottom_toTopOf="#+id/guideline2"
app:layout_constraintEnd_toStartOf="#+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Related
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 2 years ago.
i'm getting java.lang.NullPointerException. And i don't know how to solve it. looking for some help here
What i'v tried:
to look here java.lang.RuntimeException: Unable to start activity ComponentInfo But, it didn't help me
to clean and Rebuild project.
to Invalidate Cache and Restart in Android studio
and i'v discovered some problems in LayoutInflater.java
It cant resolve some imports"
sorry cant import images yet this is and image of errors in LayoutInflater.java
My XML file activity_main.XML:
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="Team A" />
<TextView
android:id="#+id/team_a_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="24dp"
android:gravity="center"
android:textSize="50sp"
android:text="0" />
<Button
android:id="#+id/three_points_button_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="plusThreePointsA"
android:text="+3 Points" />
<Button
android:id="#+id/two_points_button_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="plusTwoPointsA"
android:text="+2 Points" />
<Button
android:id="#+id/free_throw_button_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="plusOnePointA"
android:text="Free Throw" />
</LinearLayout>
<view
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="Team B" />
<TextView
android:id="#+id/team_b_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="24dp"
android:gravity="center"
android:textSize="50sp"
android:text="0" />
<Button
android:id="#+id/three_points_button_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="plusThreePointsB"
android:text="+3 Points" />
<Button
android:id="#+id/two_points_button_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="plusTwoPointsB"
android:text="+2 Points" />
<Button
android:id="#+id/free_throw_button_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="plusOnePointB"
android:text="Free Throw" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center"
android:orientation="vertical">
<Button
android:id="#+id/reset_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="24dp"
android:onClick="reset"
android:text="Reset" />
</LinearLayout>
</LinearLayout>
My MainActivity.java
package com.example.problems;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
int scoreA = 0;
int scoreB = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void plusThreePointsA(View view){
scoreA = scoreA+3;
displayScoreA(scoreA);
}
public void plusTwoPointsA(View view){
scoreA = scoreA+2;
displayScoreA(scoreA);
}
public void plusOnePointA(View view){
scoreA = scoreA+1;
displayScoreA(scoreA);
}
public void plusThreePointsB(View view){
scoreB = scoreB+3;
displayScoreB(scoreB);
}
public void plusTwoPointsB(View view){
scoreB = scoreB+2;
displayScoreB(scoreB);
}
public void plusOnePointB(View view){
scoreB = scoreB+1;
displayScoreB(scoreB);
}
public void displayScoreA (int score){
TextView viewScore = findViewById(R.id.team_a_score);
viewScore.setText(String.valueOf(score));
}
public void displayScoreB (int score){
TextView viewScore = findViewById(R.id.team_b_score);
viewScore.setText(String.valueOf(score));
}
public void reset (View view){
scoreA = 0;
scoreB = 0;
displayScoreA(scoreA);
displayScoreB(scoreB);
}
}
Error that i get
--------- beginning of crash
05-11 08:14:25.720 4084-4084/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.problems, PID: 4084
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.problems/com.example.problems.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:715)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.example.problems.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
05-11 08:19:26.000 4084-4084/com.example.problems I/Process: Sending signal. PID: 4084 SIG: 9
Use :
<View android:layout_width="1dp" android:layout_height="match_parent" android:background="#android:color/darker_gray" />
instead of :
<view
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
/>
I am new to Android and I started making my first application following tutorials and such. However, when I click the run button it gives me following error on the logcat from which I count not identify where the error is. Hence, here is my code in hope of some advice. Thanks in advance.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText firstnum = (EditText) findViewById(R.id.numberinput);
TextView resultTextView = (TextView) findViewById(R.id.resulttextview);
int num1 = Integer.parseInt(firstnum.getText().toString()) ;
int result = num1 * num1;
resultTextView.setText(result + "");
}
});
}
}
LogCat after fixing the render problem :
7-16 01:27:14.359 10870-10870/com.example.abarimess.myfirstapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.abarimess.myfirstapp, PID: 10870
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.abarimess.myfirstapp/com.example.abarimess.myfirstapp.MainActivity}: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x4
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3294)
at android.app.ActivityThread.access$1000(ActivityThread.java:210)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1704)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x4
at android.content.res.TypedArray.getDimensionPixelOffset(TypedArray.java:546)
at android.support.constraint.ConstraintLayout$LayoutParams.<init>(ConstraintLayout.java:2685)
at android.support.constraint.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:1915)
at android.support.constraint.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:476)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:820)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:467)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.abarimess.myfirstapp.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:6575)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3294)
at android.app.ActivityThread.access$1000(ActivityThread.java:210)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1704)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
And the layout XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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=".MainActivity"
tools:layout_editor_absoluteY="73dp">
<TextView
android:id="#+id/textView3"
android:layout_width="360dp"
android:layout_height="119dp"
android:layout_marginTop="50dp"
android:text="#string/square_of_the_number_is"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
android:textColor="#android:color/holo_purple"
android:textSize="40sp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.49"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/numberinput" />
<TextView
android:id="#+id/Resulttextview"
android:layout_width="390dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:background="#android:color/holo_red_dark"
android:text="#string/the_result_is"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
android:textColor="#ffffff"
android:textSize="50sp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/resulttextview"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="30dp"
android:background="#android:color/darker_gray"
android:text="#string/_0"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
android:textColor="#color/Optional"
android:textSize="40sp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.51"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Resulttextview" />
<Button
android:id="#+id/btn"
android:layout_width="370dp"
android:layout_height="80dp"
android:layout_marginTop="50dp"
android:background="?android:attr/colorActivatedHighlight"
android:text="#string/butan"
android:textColor="#android:color/holo_blue_bright"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<EditText
android:id="#+id/numberinput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="50dp"
android:ems="10"
android:hint="#string/number_in_here"
android:inputType="numberDecimal"
android:singleLine="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/resulttextview" />
</android.support.constraint.ConstraintLayout>
the manifest.Xml as requested in the comments :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.abarimess.myfirstapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
In your layout xml file, you have two separate TextView which are the following.
<TextView
android:id="#+id/Resulttextview"
android:layout_width="390dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:background="#android:color/holo_red_dark"
android:text="#string/the_result_is"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
android:textColor="#ffffff"
android:textSize="50sp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/resulttextview"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="30dp"
android:background="#android:color/darker_gray"
android:text="#string/_0"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
android:textColor="#color/Optional"
android:textSize="40sp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.51"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Resulttextview" />
Name of both text views are identical except the first one has started with a capital R. You might consider the name of the first TextView to something else like resulttextview1 like the following.
<TextView
android:id="#+id/resulttextview1"
android:layout_width="390dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:background="#android:color/holo_red_dark"
android:text="#string/the_result_is"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
android:textColor="#ffffff"
android:textSize="50sp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/resulttextview"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="30dp"
android:background="#android:color/darker_gray"
android:text="#string/_0"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
android:textColor="#color/Optional"
android:textSize="40sp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.51"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/resulttextview1" />
Please avoid naming layout identifiers with capital letters. Use underscores instead (e.g. result_text_view).
Another potential problem in your code is, if there is nothing entered in your EditText the app will crash again with a NullPointerException as the value which will be returned from firstnum.getText().toString() will have the null value.
In this case, you might consider adding a null checking here.
#Override
public void onClick(View v) {
EditText firstnum = (EditText) findViewById(R.id.numberinput);
TextView resultTextView = (TextView) findViewById(R.id.resulttextview);
// Add a null check here for safety
if(firstnum.getText().toString() == null) return;
int num1 = Integer.parseInt(firstnum.getText().toString()) ;
int result = num1 * num1;
resultTextView.setText(result + "");
}
You will get NumberFormatException in case of entering a string in your EditText other than a number. So you might need to handle that case as well. However, this can be ignored in case of handling only numbers in your EditText.
this Is because you should to instance
EditText firstnum = (EditText) findViewById(R.id.numberinput);
Out of method on click listener.
The layout_editor_absoluteX attribute for the resulttextview in your layout XML is referencing spotShadowAlpha, which is an integer which can't be explicitly converted to a dimension, as it doesn't contain any units.
You should update this value to a dimension. For example:
app:layout_editor_absoluteX="30dp"
Obviously, you'll need to change this example up to fit the rest of your layout.
Can anyone tell me what I am missing, this is driving me crazy.
Below is the java code for the Profile Activity. I've only been at this for about 30 days now and a lot is still confusing to me.
When I run the emulator, it opens, then crashes after the first button
that is supposed to send the user to the second activity.
Running Logcat, it gets hung up on line 26 of the page posted below, stating it hates something about my Listener for Button 2.
Help???
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class ProfileActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
// Button Click Goes to Main Activity
Button button1 = (Button) findViewById(R.id.start_over);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
back();
}
});
// Button Click Goes To Third Activity
Button button2 = (Button) findViewById(R.id.forward);
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
forward();
}
});
}
private void back() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
private void forward() {
Intent intent = new Intent(this, ThirdActivity.class);
startActivity(intent);
}
}
Logcat File is below:
FATAL EXCEPTION: main
Process: com.defy, PID: 2481
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.defy/com.defy.ProfileActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.defy.ProfileActivity.onCreate(ProfileActivity.java:26)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
MainActivity .XML Below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.defy.trailmaster.MainActivity">
<ImageView
android:id="#+id/background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop"
android:src="#drawable/background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="#+id/start_hiking"
android:layout_width="95dp"
android:layout_height="35dp"
android:background="#000000"
android:text="#string/app_start"
android:textColor="#FDFEFE"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.868"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.966"
tools:layout_editor_absoluteX="242dp" />
<ImageView
android:id="#+id/tent"
android:layout_width="121dp"
android:layout_height="96dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26"
app:srcCompat="#drawable/tent" />
<ImageView
android:id="#+id/hiker_right"
android:layout_width="92dp"
android:layout_height="90dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="37dp"
android:layout_marginTop="8dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.991"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.889"
app:srcCompat="#drawable/hiker_right"
tools:ignore="MissingConstraints,RtlHardcoded" />
</android.support.constraint.ConstraintLayout>
Main Activity .JAVA Below:
package com.defy.trailmaster;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Button Click Goes To Profile Activity
Button button = (Button) findViewById(R.id.start_hiking);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
hike();
}
});
}
private void hike() {
Intent intent = new Intent(this, ProfileActivity.class);
startActivity(intent);
}
}
Last is the Manifest file Below:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ProfileActivity" />
<activity android:name=".ThirdActivity"></activity>
</application>
Profile Activity XML Below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/activity_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.defy.trailmaster.ProfileActivity">
<ImageView
android:id="#+id/background"
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop"
android:src="#drawable/background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="#+id/start_over"
android:layout_width="95dp"
android:layout_height="35dp"
android:background="#000000"
android:text="#string/app_back"
android:textColor="#FDFEFE"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.145"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.966" />
<Button
android:id="#+id/hike_now"
android:layout_width="95dp"
android:layout_height="35dp"
android:background="#000000"
android:text="#string/app_hike"
android:textColor="#FDFEFE"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.868"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.966" />
<ImageView
android:id="#+id/tent"
android:layout_width="121dp"
android:layout_height="96dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26"
app:srcCompat="#drawable/tent" />
<ImageView
android:id="#+id/left_hiker"
android:layout_width="92dp"
android:layout_height="90dp"
android:layout_marginBottom="0dp"
android:layout_marginStart="42dp"
android:layout_marginLeft="42dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toTopOf="#+id/start_over"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/hiker_right"
app:srcCompat="#drawable/hiker_left" />
<ImageView
android:id="#+id/hiker_right"
android:layout_width="92dp"
android:layout_height="90dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="37dp"
android:layout_marginTop="8dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.991"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.889"
app:srcCompat="#drawable/hiker_right"
tools:ignore="MissingConstraints,RtlHardcoded" />
</android.support.constraint.ConstraintLayout>
It is crashing most likely due to R.id.forward, button2 is null.
It looks like you either named the button id something else, or missed it.
Post the XML for ProfileActivity
Here's your problem. button2 should refer to hike_now
Final Button button2 = (Button) findViewById(R.id.hike_now);
I'm developing an app for my school with a timetable and a little calculator
Here's the manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.markwitt.schul_app">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:launchMode="singleTop"
android:minSdkVersion="20"
android:supportsRtl="true"
android:targetSdkVersion="25"
android:theme="#style/AppTheme">
<activity android:name=".Stundenplan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Vertretungsplan" />
<activity android:name=".Rechner" />
<activity android:name=".Overlay"></activity>
</application>
Here's the Launcher activity activity_stundenplan.xml:
<?xml version="1.0" encoding="utf-8"?>
<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:background="#color/white">
<Button
android:text="Rechner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonrechner"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="44dp"
android:layout_marginStart="44dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonvertr"
android:text="Vertretungsplan"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/Tabelle"
android:layout_alignEnd="#+id/Tabelle" />
<TableLayout
android:id="#+id/Tabelle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.markwitt.schul_app.Stundenplan"
android:background="#color/white"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="#string/r10"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:textStyle="normal|bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r20"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:textStyle="normal|bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r30"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:textStyle="normal|bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r40"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:textStyle="normal|bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r50"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:textStyle="normal|bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r60"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:textStyle="normal|bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="#string/r11"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:textStyle="normal|bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView android:text="#string/r21" android:padding="10dp"
android:background="#drawable/cell_shape"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r31"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r41"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r51"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r61"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="#string/r12"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:textStyle="normal|bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r22"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r32"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r42"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r52"
android:padding="10dp"
android:background="#drawable/cell_shape"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="#string/r62"
android:padding="10dp"
android:background="#drawable/cell_shape"
//more TableRows
</TableLayout>
</Relativelayout>
I've made an Intent in Stundenplan.java:
rechner.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(Stundenplan.this, Rechner.class));
}
});
The Problem is that everytime I debug-launch the app on my Xperia Z3 and press the button to open the "Rechner"-Activity, the app closes and it shows me the following error:(sry for the bad format)
I/OpenGLRenderer: Initialized EGL, version 1.4
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#f97be6e time:6061206
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#f97be6e time:6065998
I/Timeline: Timeline: Activity_launch_request id:com.example.markwitt.schul_app time:6074313
D/AndroidRuntime: Shutting down VM
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.markwitt.schul_app, PID: 22562
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.markwitt.schul_app/com.example.markwitt.schul_app.Rechner}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2375)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:5526)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:116)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:29)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:203)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:193)
at com.example.markwitt.schul_app.Rechner.<init>(Rechner.java:16)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2365)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:5526)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I/Process: Sending signal. PID: 22562 SIG: 9
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'
My Rechner.java and my activity_rechner look like this:
package com.example.markwitt.schul_app;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class Rechner extends AppCompatActivity {
private RadioGroup radioGroup;
private RadioButton checked;
private Button los;
public String mode;
EditText number1 = (EditText) findViewById(R.id.nummer1);
EditText number2 = (EditText) findViewById(R.id.nummer2);
EditText ergebnis = (EditText) findViewById(R.id.ergebnis);
public int text1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rechner);
addListenerOnButton();
}
public void addListenerOnButton() {
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
los = (Button) findViewById(R.id.button5);
los.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int selectedId = radioGroup.getCheckedRadioButtonId();
checked = (RadioButton) findViewById(selectedId);
switch (checked.getId()){
case R.id.plus: mode = "+";
case R.id.minus: mode = "-";
case R.id.mal: mode = "*";
case R.id.geteilt: mode = ":";
case R.id.fakultaet: mode = "fak";
}
text1 = Integer.parseInt(number1.getText().toString());
int text2 = Integer.parseInt(number2.getText().toString());
switch (mode){
case "+": ergebnis.setText(text1 + text2);
case "-": ergebnis.setText(text1 - text2);
case "*": ergebnis.setText(text1 * text2);
case ":": ergebnis.setText(text1 / text2);
case "fak": ergebnis.setText(Long.toString(fakultaet(text1)));
}
}
});
}
static long fakultaet(int n) {
int ergebnis = 1;
for (int i = 1; i <= n; i++) {
ergebnis = ergebnis * i;
}
return ergebnis;
}
}
...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_durchschnitt"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.markwitt.schul_app.Rechner">
<EditText
android:id="#+id/nummer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:layout_weight="1"
android:ems="10"
android:hint="Nummer 1"
android:inputType="number"
android:maxLines="1"
android:textAlignment="center" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/ergebnis"
android:layout_centerHorizontal="true"
android:layout_marginBottom="22dp"
android:text="=" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/nummer1"
android:layout_marginEnd="42dp"
android:layout_marginRight="42dp"
android:layout_marginTop="69dp"
android:orientation="horizontal">
<RadioButton
android:id="#+id/mal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/geteilt"
android:layout_alignBottom="#+id/geteilt"
android:layout_toLeftOf="#+id/geteilt"
android:layout_toStartOf="#+id/geteilt"
android:layout_weight="1"
android:text="* "
android:textAllCaps="true"
android:textStyle="bold" />
<RadioButton
android:id="#+id/fakultaet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/mal"
android:layout_alignBottom="#+id/mal"
android:layout_toLeftOf="#+id/mal"
android:layout_toStartOf="#+id/mal"
android:layout_weight="1"
android:text="Fakultät "
android:textAllCaps="true"
android:textStyle="bold" />
<RadioButton
android:id="#+id/plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/minus"
android:layout_alignBottom="#+id/minus"
android:layout_toEndOf="#+id/nummer1"
android:layout_toRightOf="#+id/nummer1"
android:layout_weight="1"
android:text="+ "
android:textAllCaps="true"
android:textStyle="bold" />
<RadioButton
android:id="#+id/geteilt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/radioGroup"
android:layout_toEndOf="#+id/radioGroup"
android:layout_toRightOf="#+id/radioGroup"
android:layout_weight="1"
android:text=": "
android:textAllCaps="true"
android:textStyle="bold" />
<RadioButton
android:id="#+id/minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/geteilt"
android:layout_alignBottom="#+id/geteilt"
android:layout_toLeftOf="#+id/plus"
android:layout_toStartOf="#+id/plus"
android:layout_weight="1"
android:text="- "
android:textAllCaps="true"
android:textStyle="bold" />
</RadioGroup>
<EditText
android:id="#+id/ergebnis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/nummer2"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/nummer2"
android:layout_marginBottom="61dp"
android:ems="10"
android:hint="Ergebnis"
android:inputType="number"
android:textAlignment="center" />
<EditText
android:id="#+id/nummer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/nummer1"
android:layout_alignStart="#+id/nummer1"
android:layout_centerVertical="true"
android:ems="10"
android:hint="Nummer 2"
android:inputType="number"
android:textAlignment="center" />
</RelativeLayout>
Can you please give me an answer what to do? It does the same on my phone and on my emulator
If you have questions, contact me please!
PS: I have to finish it till the 12th December
You cannot use findviewbyid before you set the content view. It returns null and that's your exception.
Change your code to something like that:
EditText number1;
EditText number2;
EditText ergebnis;
public int text1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rechner);
number1 = (EditText) findViewById(R.id.nummer1);
number2 = (EditText) findViewById(R.id.nummer2);
ergebnis = (EditText) findViewById(R.id.ergebnis);
addListenerOnButton();
}
Also, Ill recommend you to read the android code style recommendations.
https://source.android.com/source/code-style.html
I'm making a pretty basic 6-7 activity app, trying to keep it really simple. I've succesfully added 4 other instances where at the bottom of the app you press "NEXT" and it takes you to the next activity in the app. However, I'm stuck and can't figure out how to continue. I've tried debugging and can't figure out what the error message means. THanks for your help.
The error message from Logcat:
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:4785)
at android.view.View$PerformClick.run(View.java:19884)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4785)
at android.view.View$PerformClick.run(View.java:19884)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.widget.TextView.getText()' on a null object reference
at com.example.android.budgeit10.expenses.fourthNext(expenses.java:86)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4785)
at android.view.View$PerformClick.run(View.java:19884)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
JAVA:
package com.example.android.budgeit10;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class expenses extends AppCompatActivity {
AppCompatActivity appCompatActivity;
EditText housingExpense;
EditText foodExpense;
EditText transportExpense;
EditText otherExpense;
Button expensesButton;
TextView addExpenses;
EditText income;
double housing, food, transport, other, sum;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_expenses);
housingExpense = (EditText) findViewById(R.id.housingExpense);
foodExpense = (EditText) findViewById(R.id.foodExpense);
transportExpense = (EditText) findViewById(R.id.transportExpense);
otherExpense = (EditText) findViewById(R.id.otherExpense);
expensesButton = (Button) findViewById(R.id.expensesButton);
addExpenses = (TextView) findViewById(R.id.totalMonthlyExpenses);
income = (EditText) findViewById(R.id.monthlyIncome);
expensesButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
housing = Double.parseDouble(housingExpense.getText().toString());
try {
Double.parseDouble(housingExpense.getText().toString());
} catch (NumberFormatException nfe) {
}
food = Double.parseDouble(foodExpense.getText().toString());
transport = Double.parseDouble(transportExpense.getText().toString());
other = Double.parseDouble(otherExpense.getText().toString());
sum = housing + food + transport + other;
addExpenses.setText(Double.toString(sum));
}
});
expensesButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (TextUtils.isEmpty(housingExpense.getText().toString()) ||
TextUtils.isEmpty(foodExpense.getText().toString()) ||
TextUtils.isEmpty(otherExpense.getText().toString()) ||
TextUtils.isEmpty(transportExpense.getText().toString())) {
addExpenses.setText("Please fill all fields."); // if any of the fields is empty, add nothing to textview
} else {
Double housing = Double.parseDouble(housingExpense.getText().toString());
Double food = Double.parseDouble(foodExpense.getText().toString());
Double transport = Double.parseDouble(transportExpense.getText().toString());
Double other = Double.parseDouble(otherExpense.getText().toString());
Double sum = housing + food + transport + other;
addExpenses.setText(Double.toString(sum));
}
}
});
}
public void fourthNext(View view) {
Intent intent = new Intent(this, Goals.class);
TextView textView = (TextView) findViewById(R.id.totalMonthlyIncome);
String income = textView.getText().toString();
startActivity(intent);
}
XML from Button:
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.android.budgeit10.incomePage">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="MONTHLY EXPENSES"
android:textSize="24dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/totalMonthlyIncome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:text="Enter Monthly Income"
android:textSize="22dp"
android:textStyle="bold" />
<EditText
android:id="#+id/monthlyIncome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/income_on_expenses"
android:inputType="phone"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#2E7D32" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="HOUSING"
android:textSize="22dp"
android:textStyle="bold" />
<EditText
android:id="#+id/housingExpense"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/housing"
android:inputType="phone"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:paddingTop="16dp"
android:text="FOOD"
android:textSize="22dp"
android:textStyle="bold" />
<EditText
android:id="#+id/foodExpense"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/food"
android:inputType="phone"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:paddingTop="16dp"
android:text="TRANSPORTATION"
android:textSize="22dp"
android:textStyle="bold" />
<EditText
android:id="#+id/transportExpense"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/transport"
android:inputType="phone"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:paddingTop="16dp"
android:text="EVERYTHING ELSE"
android:textSize="22dp"
android:textStyle="bold" />
<EditText
android:id="#+id/otherExpense"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/other"
android:inputType="phone"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#2E7D32" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="16dp">
<Button
android:id="#+id/expensesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#C8E6C9"
android:onClick="submitOrder"
android:padding="16dp"
android:text="TOTAL EXPENSES"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:id="#+id/totalMonthlyExpenses"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/monthly_expenses"
android:inputType="phone"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="Extra $ : "
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:id="#+id/extra_cash"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/extra_cash"
android:inputType="phone"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textSize="16dp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/fourthNext"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:background="#C8E6C9"
android:onClick="fourthNext"
android:text="NEXT"
android:textSize="34dp">
</Button>
</RelativeLayout>
</LinearLayout>
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.budgeit10">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PageTwo" />
<activity android:name=".incomePage" />
<activity android:name=".expenses" />
<activity android:name=".Goals" />
</application>
You should have a TextView with id 'totalMonthlyIncome' in your XML layout. (According to the Java code) Just make sure that's there and it will solve the issue.
"Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.widget.TextView.getText()' on a null object reference
at com.example.android.budgeit10.expenses.fourthNext(expenses.java:86)"
According to the logcat error is in expenses.java - line 86