I can't run my app (android studio) [duplicate] - java

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
There is the eror message on the monitor:
07-20 17:00:05.234 17194-17194/com.example.champion.courtcounter E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.champion.courtcounter/com.example.champion.courtcounter.MainActivity}: android.view.InflateException: Binary XML file line #69: Error inflating class null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2129)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2154)
at android.app.ActivityThread.access$700(ActivityThread.java:146)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1260)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4949)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #69: Error inflating class null
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.champion.courtcounter.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5185)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2154) 
at android.app.ActivityThread.access$700(ActivityThread.java:146) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1260) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4949) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NullPointerException
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:101)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:681)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:495) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.champion.courtcounter.MainActivity.onCreate(MainActivity.java:16) 
at android.app.Activity.performCreate(Activity.java:5185) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2154) 
at android.app.ActivityThread.access$700(ActivityThread.java:146) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1260) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4949) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810) 
at dalvik.system.NativeStart.main(Native Method) 
There is my xml code:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:padding="16dp"
android:text="Team A"
android:textColor="#616161"
android:textSize="14sp" />
<TextView
android:id="#+id/team_a_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:paddingBottom="24dp"
android:text="0"
android:textColor="#000000"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="points3"
android:text="+3 points" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:onClick="points2"
android:text="+2 points" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="point"
android:text="free throw" />
</LinearLayout>
<view
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:background="#android:color/darker_gray" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:padding="16dp"
android:text="Team B"
android:textColor="#616161"
android:textSize="14sp" />
<TextView
android:id="#+id/team_b_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:paddingBottom="24dp"
android:text="0"
android:textColor="#000000"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="points3B"
android:text="+3 points" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:onClick="points2B"
android:text="+2 points" />
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:onClick="pointB"
android:text="free throw" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"
android:onClick="reset"
android:text="reset" />
</RelativeLayout>
There is my java code:
package com.example.champion.courtcounter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.example.champion.courtcounter.R;
public class MainActivity extends AppCompatActivity {
int numA=0;
int numB=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void displayForTeamA(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_a_score);
scoreView.setText(String.valueOf(score));
}
public void points3(View view) {
numA = numA + 3;
displayForTeamA(numA);
}
public void points2(View view) {
numA = numA + 2;
displayForTeamA(numA);
}
public void point(View view) {
numA = numA + 1;
displayForTeamA(numA);
}
public void displayForTeamB(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_b_score);
scoreView.setText(String.valueOf(score));
}
public void points3B(View view) {
numB = numB + 3;
displayForTeamB(numB);
}
public void points2B(View view) {
numB = numB + 2;
displayForTeamB(numB);
}
public void pointB(View view) {
numB = numB + 1;
displayForTeamB(numB);
}
public void reset(View view) {
numB = 0;
displayForTeamB(numB);
numA = 0;
displayForTeamA(numA);
}
}
I can't even open it. When I try to open it's says:"Unfortunately, Court Counter(the name of my app) has stopped.
Thank for help.

<view
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:background="#android:color/darker_gray" />
Change view with View

Related

getting a java.lang.NullPointerException: in a simple app [duplicate]

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"
/>

how the second activity crash?

i just want to fill some infos in the activitymain and then pass an intent to a second activity, at the first it works perfect but when i add some xml layout, when running the app on device and pass the intent it crashes
the main activity
public void move(View view) {
Intent i = new Intent(MainActivity.this, FormActivity.class);
EditText name = findViewById(R.id.name);
EditText animal = findViewById(R.id.animal);
String n = name.getText().toString();
String a = animal.getText().toString();
if (n.isEmpty() || a.isEmpty()) {
Toast.makeText(this, "nom ou animal est vide !", Toast.LENGTH_SHORT).show();
} else {
i.putExtra("KEY_Name", name.getText().toString());
i.putExtra("KEY_Animal", animal.getText().toString());
startActivity(i);
}
}
// and the formactivity or the second
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form);
Intent i = getIntent();
TextView Text1 = findViewById(R.id.t1);
TextView Text2 = findViewById(R.id.t2);
String name = i.getStringExtra("KEY_Name");
String animal = i.getStringExtra("KEY_Animal");
Text1.setText(name);
Text2.setText(animal);
}
// XML file for activity_main it works perfect
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/dog" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="40dp"
android:src="#drawable/logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:shadowColor="#000000"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:text="#string/hello"
android:textColor="#ffffff"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView"
app:layout_constraintVertical_bias="0.075" />
<LinearLayout
android:id="#+id/linear1"
style="#style/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:shadowColor="#000000"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:text="#string/name"
android:textColor="#ffffff" />
<View
android:layout_width="3dip"
android:layout_height="match_parent"
android:background="#ffffff" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="#string/ex_name"
android:inputType="textCapWords"
android:maxLines="1" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#ffffff"
app:layout_constraintBottom_toTopOf="#+id/linear2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/linear2" />
<LinearLayout
android:id="#+id/linear2"
style="#style/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:shadowColor="#000000"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:text="#string/pet"
android:textColor="#ffffff" />
<View
android:layout_width="3dip"
android:layout_height="match_parent"
android:background="#ffffff" />
<EditText
android:id="#+id/animal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="#string/ex_animal"
android:inputType="textCapWords"
android:maxLines="1" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:onClick="move"
android:text="Suivant"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.096"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear2"
app:layout_constraintVertical_bias="0.344" />
// the activity_form or second that crashes
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/sheep" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:foregroundGravity="center_horizontal"
android:src="#drawable/title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:background="#drawable/list_fluid"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="#+id/t1"
android:layout_width="match_parent"
android:layout_height="25dp"
android:gravity="center_horizontal"
android:text="Hello freind!"
android:textColor="#color/green"
android:textSize="24sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginBottom="12dp"
android:layout_marginTop="12dp"
android:background="#ffffff" />
<TextView
android:id="#+id/t2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="oh, puppy!"
android:textColor="#color/green"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginTop="12dp"
android:text="comment Aidez-Vous ?" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="mon Chat souffre de fièvre"
android:inputType="text"
android:lines="6"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc"
android:textSize="12sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:background="#color/logo"
android:text="envoyer"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
the logcat
10-09 18:03:08.327 29724-29724/com.example.android.workingproject W/ResourceType: Failure getting entry for 0x01080946 (t=7 e=2374) (error -75)
10-09 18:04:20.737 29724-29724/com.example.android.workingproject W/ResourceType: Failure getting entry for 0x01080946 (t=7 e=2374) (error -75)
10-09 18:04:21.538 29724-29724/com.example.android.workingproject E/art: Throwing OutOfMemoryError "Failed to allocate a 343944636 byte allocation with 16777120 free bytes and 52MB until OOM"
10-09 18:04:21.608 29724-29724/com.example.android.workingproject E/art: Throwing OutOfMemoryError "Failed to allocate a 343944636 byte allocation with 16777120 free bytes and 52MB until OOM"
10-09 18:04:21.628 29724-29724/com.example.android.workingproject E/art: li.han, Prepare to dump hprof for OOM Error !
li.han, Directory [/data/log] could not be write !
10-09 18:04:21.638 29724-29724/com.example.android.workingproject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.workingproject, PID: 29724
java.lang.OutOfMemoryError: Failed to allocate a 343944636 byte allocation with 16777120 free bytes and 52MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:837)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:656)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1037)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4056)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.loadDrawable(Resources.java:3779)
at android.content.res.TypedArray.getDrawable(TypedArray.java:776)
at android.widget.ImageView.<init>(ImageView.java:151)
at android.widget.ImageView.<init>(ImageView.java:140)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
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:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.android.workingproject.FormActivity.onCreate(FormActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3103)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3260)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1734)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6934)
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)
At least one of the drawables referenced in your second XML file is too big.
Check the following drawables and resize them:
sheep
title
list_fluid
PNGs generally don't need to be very large. Keep them below 1600x1600 if you can, preferably 800x800.

App crashes when I try to go to Next Activity Page in App

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

Can't run App on Note 2 because of too many images (only 20 images)

I am getting the following error when I go from my Main Activity page to my New Activity page. The New Activity page crashes unless it has <10 images or so, which is pathetic (the app runs fine emulated on my computer, however):
06-22 16:53:04.841 15058-15058/? D/AndroidRuntime: Shutting down VM
06-22 16:53:04.841 15058-15058/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41e35c08)
06-22 16:53:04.851 15058-15058/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.matthewscompany.matthew.test1, PID: 15058
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:683)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:513)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:889)
at android.content.res.Resources.loadDrawable(Resources.java:3436)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ImageView.<init>(ImageView.java:133)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:102)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:972)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1030)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
at com.example.matthew.test1.NewActivity.onCreate(NewActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
06-22 16:53:04.861 2430-2769/? W/ActivityManager: Force finishing activity com.matthewscompany.matthew.test1/com.example.matthew.test1.NewActivity
06-22 16:53:04.866 2430-2769/? W/ActivityManager: Force finishing activity com.matthewscompany.matthew.test1/com.example.matthew.test1.MainActivity
I understand that the out of memory error occurs when the ram for a phone runs out when processing too many bitmaps.
Yes, I have read the Android Developer webpages on tips for processing bitmaps. However, I still don't understand which groups of code from their guides I'm supposed to insert, and where I'm supposed to insert it. I've tried inserting some of their stuff into my .java files but I just end up getting errors. I owe this to me being a beginner at Java and not understanding how to apply the example codes.
Again, I am a beginner to Java and Android Studio so please go easy on me and explain things as simply as you can, if possible.
Here's my code:
MainActivity.java:
package com.example.matthew.test1;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends AppCompatActivity {
//Main Menu
//Main Activity Mario Icon:
ImageButton Mario;
ImageButton Luigi;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Mario= (ImageButton) findViewById(R.id.Mario);
Mario.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intentLoadNewActivity = new Intent(MainActivity.this, NewActivity.class);
startActivity(intentLoadNewActivity);
}
});
Luigi= (ImageButton) findViewById(R.id.Luigi);
Luigi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intentLoadNewActivity = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intentLoadNewActivity);
}
});
}
}
NewActivity.java:
public class NewActivity extends AppCompatActivity implements View.OnClickListener {
ViewFlipper viewFlipper;
Button next;
Button previous;
TextView pageCounter;
int count = 1;
private static final int TOTAL_IMG_COUNT = 23;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);
viewFlipper = (ViewFlipper)findViewById(R.id.viewFlipper);
next = (Button) findViewById(R.id.next);
previous = (Button) findViewById(R.id.previous);
pageCounter = (TextView)findViewById(R.id.textView2);
pageCounter.setText(String.valueOf(count));
next.setOnClickListener(this);
previous.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if (v == next) {
viewFlipper.showNext();
if (next.getId() == (R.id.ImageView23)) {
count = 1;
} else {
count++;
}
pageCounter.setText(String.valueOf(count) + "/" + TOTAL_IMG_COUNT);
}
else if (v == previous) {
viewFlipper.showPrevious();
if(previous.getId() == (R.id.ImageView1)) {
count = TOTAL_IMG_COUNT;
} else {
count--;
}
pageCounter.setText(String.valueOf(count) + "/" + TOTAL_IMG_COUNT);
}
}
}
content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.matthew.test1.MainActivity"
tools:showIn="#layout/activity_main">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Mario"
android:src="#drawable/mario_select"
android:layout_above="#+id/samus_select"
android:layout_alignLeft="#+id/samus_select"
android:layout_alignStart="#+id/samus_select" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Luigi"
android:src="#drawable/luigi_select"
android:layout_above="#+id/samus_select"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dk_select"
android:src="#drawable/dk_select"
android:layout_above="#+id/falcon_select"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/link_select"
android:src="#drawable/link_select"
android:layout_below="#+id/fox_select"
android:layout_alignParentLeft="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/samus_select"
android:src="#drawable/samus_select"
android:layout_above="#+id/kirby_select"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/falcon_select"
android:src="#drawable/falcon_select"
android:layout_alignTop="#+id/samus_select"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ness_select"
android:src="#drawable/ness_select"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/yoshi_select"
android:src="#drawable/yoshi_select"
android:layout_below="#+id/falcon_select"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/kirby_select"
android:src="#drawable/kirby_select"
android:layout_above="#+id/pika_select"
android:layout_alignLeft="#+id/samus_select"
android:layout_alignStart="#+id/samus_select" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fox_select"
android:src="#drawable/fox_select"
android:layout_alignParentStart="true"
android:layout_below="#+id/Luigi"
android:layout_alignParentLeft="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pika_select"
android:src="#drawable/pika_select"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/kirby_select"
android:layout_alignStart="#+id/kirby_select" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/jiggly_select"
android:src="#drawable/jiggly_select"
android:layout_below="#+id/yoshi_select"
android:layout_alignLeft="#+id/yoshi_select"
android:layout_alignStart="#+id/yoshi_select" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Hitbox64"
android:id="#+id/textView"
android:textSize="48dp"
android:layout_above="#+id/Mario"
android:layout_centerHorizontal="true" />
</RelativeLayout>
activity_new.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"
tools:context="com.example.matthew.test1.NewActivity">
<ViewFlipper
android:layout_width="480dp"
android:layout_height="480dp"
android:id="#+id/viewFlipper">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView1"
android:scaleType="centerCrop"
android:src="#drawable/b1"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView2"
android:scaleType="centerCrop"
android:src="#drawable/b2"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView3"
android:scaleType="centerCrop"
android:src="#drawable/b3"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView4"
android:scaleType="centerCrop"
android:src="#drawable/b4"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView5"
android:scaleType="centerCrop"
android:src="#drawable/b5"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView6"
android:scaleType="centerCrop"
android:src="#drawable/b6"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView7"
android:scaleType="centerCrop"
android:src="#drawable/b7"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView8"
android:scaleType="centerCrop"
android:src="#drawable/b8"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView9"
android:scaleType="centerCrop"
android:src="#drawable/b9"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView10"
android:scaleType="centerCrop"
android:src="#drawable/b10"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView11"
android:scaleType="centerCrop"
android:src="#drawable/b11"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView12"
android:scaleType="centerCrop"
android:src="#drawable/b12"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView13"
android:scaleType="centerCrop"
android:src="#drawable/b13"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView14"
android:scaleType="centerCrop"
android:src="#drawable/b14"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView16"
android:scaleType="centerCrop"
android:src="#drawable/b17"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView18"
android:scaleType="centerCrop"
android:src="#drawable/b18"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView19"
android:scaleType="centerCrop"
android:src="#drawable/b19"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView20"
android:scaleType="centerCrop"
android:src="#drawable/b20"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView21"
android:scaleType="centerCrop"
android:src="#drawable/b21"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView22"
android:scaleType="centerCrop"
android:src="#drawable/b22"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ImageView23"
android:scaleType="centerCrop"
android:src="#drawable/b23"/>
</ViewFlipper>
<Button
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<Button
android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prev"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignTop="#+id/next"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Frame Counter"
android:id="#+id/textView2"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Bair"
android:id="#+id/textView3"
android:layout_alignTop="#+id/previous"
android:layout_centerHorizontal="true" />
</RelativeLayout>
If your images are too high-resolution, they can eat up a LOT of memory, especially if you have 20 of them as you say. Consider using Picasso or some other library to load your images.

Dialg - ImageView - NullPointerException - setOnClickListener

I have a NullpointerException but i can't figure out why! please your help as i'm struggling with it :
Here's my XML resource :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="20dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_speciality_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: " />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="add:" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="phone :" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="abc abc abc" />
<TextView
android:id="#+id/textView44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="abc" />
<TextView
android:id="#+id/textView55"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="230020202" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageViewClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#drawable/close_selector" />
</RelativeLayout>
Below my Java instructions :
The setContentView is before the use of the actual TextView
final Dialog dialog = new Dialog(searchActivity.this);
dialog.setContentView(R.layout.custom_dialog);``
ImageView closeBtn =(ImageView)findViewById(R.id.imageViewClose);
closeBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
finish();
}
});
Logcat errros :
java.lang.NullPointerException
at com.itraan.Test.searchActivity$2.onItemClick(searchActivity.java:902)
at android.widget.AdapterView.performItemClick(AdapterView.java:308)
at android.widget.AbsListView.performItemClick(AbsListView.java:1483)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3485)
at android.widget.AbsListView$3.run(AbsListView.java:4843)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Thank you in advance.

Categories