Could not execute method for android:onClick - Parsing String to Double - java

I'm trying to create a Android app but I'm getting an error when clicking a button.
What I'm trying to do is convert a String to a double. I can't use the text field as a number, because I'm working with latitude and longitude, so I need negative numbers, and type="number" doesn't allow that.
This is the function that I execute:
public void insertSite(View view) {
String type = ((AutoCompleteTextView)findViewById(R.id.type)).getText().toString();
String address = ((AutoCompleteTextView)findViewById(R.id.address)).getText().toString();
String city = ((AutoCompleteTextView)findViewById(R.id.city)).getText().toString();
String district = ((AutoCompleteTextView)findViewById(R.id.district)).getText().toString();
String cep = ((AutoCompleteTextView)findViewById(R.id.cep)).getText().toString();
String state = ((AutoCompleteTextView)findViewById(R.id.state)).getText().toString();
double latitude = Double.parseDouble(((EditText)findViewById(R.id.latitude)).getText().toString());
double longitude = Double.parseDouble(((AutoCompleteTextView)findViewById(R.id.longitude)).getText().toString());
double altitude = Double.parseDouble(((AutoCompleteTextView)findViewById(R.id.altitude)).getText().toString());
try {
VivoDbDAO dao = new VivoDbDAO(this);
dao.insertSite(
type,
address,
city,
district,
state,
cep,
latitude,
longitude,
altitude);
Toast.makeText(this, "Site 1 inserido", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, CadastroImovel2Activity.class);
startActivity(intent);
finish();
} catch (Exception e) {
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}
}
And here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/cadastroImovel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha=".9"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.thiago.muitogelo.CadastroActivity"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="?attr/colorPrimary"
android:backgroundTint="#color/roxoVivo"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:title="Dr. Antena" />
</android.support.design.widget.AppBarLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="40dp" />
<ScrollView
android:layout_width="300dp"
android:layout_height="350dp"
android:layout_gravity="center">
<LinearLayout
android:layout_width="300dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<AutoCompleteTextView
android:id="#+id/type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/text_field"
android:elevation="5dp"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:hint="Prédio ou Térreo?"
android:textColor="#color/roxoEscuro" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<AutoCompleteTextView
android:id="#+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/text_field"
android:elevation="5dp"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:hint="Endereço"
android:textColor="#color/roxoEscuro" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<AutoCompleteTextView
android:id="#+id/city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/text_field"
android:elevation="5dp"
android:inputType="phone"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:hint="Cidade"
android:textColor="#color/roxoEscuro" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<AutoCompleteTextView
android:id="#+id/district"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/text_field"
android:elevation="5dp"
android:inputType="text"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:hint="Bairro"
android:textColor="#color/roxoEscuro" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<AutoCompleteTextView
android:id="#+id/state"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/text_field"
android:elevation="5dp"
android:inputType="text"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:hint="Estado"
android:textColor="#color/roxoEscuro" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<AutoCompleteTextView
android:id="#+id/cep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/text_field"
android:elevation="5dp"
android:inputType="number"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:hint="CEP"
android:textColor="#color/roxoEscuro" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<EditText
android:id="#+id/latitude"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/button2"
android:inputType="text"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:hint="Latitude"
android:textColor="#color/roxoEscuro" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<AutoCompleteTextView
android:id="#+id/longitude"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/button2"
android:inputType="text"
android:hint="Longitude"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:textColor="#color/roxoEscuro"
android:clickable="false" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<AutoCompleteTextView
android:id="#+id/altitude"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/button2"
android:inputType="text"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:hint="Altitude"
android:textColor="#color/roxoEscuro"
android:clickable="false" />
</LinearLayout>
</ScrollView>
<Space
android:layout_width="wrap_content"
android:layout_height="40dp" />
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:weightSum="2"
android:layout_gravity="center"
android:padding="10dp">
<Button
android:layout_width="250dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="#drawable/button2"
android:text="Próximo"
android:textColor="#color/roxoEscuro"
android:id="#+id/btConcluidoCadastro"
android:onClick="insertSite"
android:layout_weight="2"/>
</LinearLayout>
</LinearLayout>
And here is the log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.thiago.muitogelo, PID: 334
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:5716)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22596)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5716) 
at android.widget.TextView.performClick(TextView.java:10926) 
at android.view.View$PerformClick.run(View.java:22596) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:7325) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: java.lang.NumberFormatException: Invalid double: ""
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseDouble(StringToReal.java:267)
at java.lang.Double.parseDouble(Double.java:301)
at com.example.thiago.muitogelo.CadastroImovel1Activity.insertSite(CadastroImovel1Activity.java:30)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
at android.view.View.performClick(View.java:5716) 
at android.widget.TextView.performClick(TextView.java:10926) 
at android.view.View$PerformClick.run(View.java:22596) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:7325) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

The Log says that you have entered an invalid double.May be the problem is with
double latitude = Double.parseDouble(((EditText)findViewById(R.id.latitude)).getText().toString());
double longitude = Double.parseDouble(((AutoCompleteTextView)findViewById(R.id.longitude)).getText().toString());
double altitude = Double.parseDouble(((AutoCompleteTextView)findViewById(R.id.altitude)).getText().toString());
ie. The value in latitude,longitude, altitude may contains invalid double values.May be if there is no value in that field can cause this error.Use this.
if(((EditText)findViewById(R.id.latitude)).getText().toString().length()!=0&&((EditText)findViewById(R.id.longitude))).getText().toString().length()!=0&&((EditText)findViewById(R.id.altitude)).getText().toString().length()!=0){
double latitude = Double.parseDouble(((EditText)findViewById(R.id.latitude)).getText().toString());
double longitude = Double.parseDouble(((AutoCompleteTextView)findViewById(R.id.longitude)).getText().toString());
double altitude = Double.parseDouble(((AutoCompleteTextView)findViewById(R.id.altitude)).getText().toString());}

It seems that you are trying to create a double out of an empty string. How about check field contents for empty values before parsing it as a double?

Related

Unable to start activity crash decorcontent parent

Unable to start activity Component Info ERROR
When im starting my app, its skippp all the ativity and goes at the somewhere activity and after 3 seconds it finally crashes.
its show no visible error on my java and xml...
im having error on my logcat
idont know where is the error
2019-10-16 05:55:20.542 23865-23865/com.ilsproj.ilovebatangas E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ilsproj.ilovebatangas, PID: 23865
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ilsproj.ilovebatangas/com.ilsproj.ilovebatangas.ui.CategorySelection}: java.lang.NullPointerException: Attempt to invoke interface method 'void androidx.appcompat.widget.DecorContentParent.setWindowCallback(android.view.Window$Callback)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:169)
at android.app.ActivityThread.main(ActivityThread.java:6521)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void androidx.appcompat.widget.DecorContentParent.setWindowCallback(android.view.Window$Callback)' on a null object reference
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:753)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:659)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:552)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.ilsproj.ilovebatangas.ui.CategorySelection.onCreate(CategorySelection.java:20)
at android.app.Activity.performCreate(Activity.java:7051)
at android.app.Activity.performCreate(Activity.java:7042)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:169) 
at android.app.ActivityThread.main(ActivityThread.java:6521) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Heres my Splashcreen.java
public class Splashsrcreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashsrcreen);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(Splashsrcreen.this,CategorySelection.class);
startActivity(i);
finish();
}
}, 3000);
}
}
My catergoryselection.java
public class CategorySelection extends AppCompatActivity {
CardView imagebutton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_category_selection);
CardView mountain = findViewById(R.id.cv_mountains);
mountain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent( CategorySelection.this, Cat_Mountains.class);
startActivity(intent);
}
});
}
}
activity_category_selection
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:weightSum="10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#color/colorPrimary"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<GridLayout
android:id="#+id/mainGrid"
android:layout_width="385dp"
android:layout_height="589dp"
android:layout_gravity="center"
android:layout_weight="8"
android:alignmentMode="alignMargins"
android:columnCount="2"
android:columnOrderPreserved="false"
android:rowCount="5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.53999996">
<androidx.cardview.widget.CardView
android:id="#+id/cv_beaches"
android:layout_width="185dp"
android:layout_height="198dp"
android:layout_margin="5dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:background="#ffff"
android:scaleType="fitCenter"
android:src="#drawable/beaches" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Beaches"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cv_mountains"
android:layout_width="185dp"
android:layout_height="198dp"
android:layout_margin="5dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:background="#ffff"
android:scaleType="fitCenter"
android:src="#drawable/mountain" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Mountains"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cv_island"
android:layout_width="185dp"
android:layout_height="198dp"
android:layout_margin="5dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:background="#ffff"
android:scaleType="fitCenter"
android:src="#drawable/island" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Island"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cv_churces"
android:layout_width="185dp"
android:layout_height="198dp"
android:layout_margin="5dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:background="#ffff"
android:scaleType="fitCenter"
android:src="#drawable/churches" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Churches"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cv_heritage"
android:layout_width="185dp"
android:layout_height="198dp"
android:layout_margin="5dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:background="#ffff"
android:scaleType="fitCenter"
android:src="#drawable/heritage" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Heritage"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</ScrollView>
This could be a caching problem.
try with:
"Android Studio: menu> Build -> Clean Project"
or
"Android Studio: menu> File -> Invalidate Caches / Restart"

Error inflating class fragment Android kotlin

Error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pockethcm.greytrix.test, PID: 6566
android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Binary XML file line #29: Duplicate id 0x7f09012d, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3680)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:420)
at android.app.Dialog.setContentView(Dialog.java:557)
at com.pockethcm.greytrix.test.Fragments.DashboardFragment.openPunchDetailDialog(DashboardFragment.kt:1183)
at com.pockethcm.greytrix.test.Fragments.DashboardFragment$sendLocationData$1.onSuccess(DashboardFragment.kt:767)
at com.pockethcm.greytrix.test.Fragments.DashboardFragment$sendLocationData$1.onSuccess(DashboardFragment.kt:102)
at com.google.android.gms.tasks.zzj.run(Unknown Source:27)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Fragment Code
var mapFragment = activity.supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
if(mapFragment != null){
mapFragment!!.getMapAsync(OnMapReadyCallback {
googleMap = it
val location1 = LatLng(13.03,77.60)
val location2 = LatLng(13.53,77.67)
googleMap.addMarker(MarkerOptions().position(location1).title("First Location"))
googleMap.addMarker(MarkerOptions().position(location2).title("Second Location"))
val center = CameraUpdateFactory.newLatLng(location1)
val zoom = CameraUpdateFactory.zoomTo(15f)
val markerPoints = LatLngBounds(
location1, location2)
googleMap.setOnMapLoadedCallback(GoogleMap.OnMapLoadedCallback {
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(markerPoints,30))
})
})
}
punchdetailLayout
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="200dp"
/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/view_layout"
android:orientation="vertical"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Address"
android:layout_weight="0.5"
android:textColor="#000000"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/address"
android:textColor="#000000"
android:layout_weight="0.5"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Locality"
android:layout_weight="0.5"
android:textColor="#000000"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/locality"
android:textColor="#000000"
android:layout_weight="0.5"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Time"
android:layout_weight="0.5"
android:textColor="#000000"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/time"
android:textColor="#000000"
android:layout_weight="0.5"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ok"
android:text="OK">
</Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Records Found!"
android:gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:visibility="gone"
android:id="#+id/no_rec"
/>
</android.support.v7.widget.CardView>

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

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