Error message--------- E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.project, PID: 29100 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.project/com.example.project.CustomCalendarActivity}: android.view.InflateException: Binary XML file line #9 in com.example.project:layout/calendar_layout_activity: Binary XML file line #9 in com.example.project:layout/calendar_layout_activity: Error inflating class com.example.project.CustomCalendarView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: android.view.InflateException: Binary XML file line #9 in com.example.project:layout/calendar_layout_activity: Binary XML file line #9 in com.example.project:layout/calendar_layout_activity: Error inflating class com.example.project.CustomCalendarView Caused by: android.view.InflateException: Binary XML file line #9 in com.example.project:layout/calendar_layout_activity: Error inflating class com.example.project.CustomCalendarView Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at android.view.LayoutInflater.createView(LayoutInflater.java:854) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084) at android.view.LayoutInflater.inflate(LayoutInflater.java:682) at android.view.LayoutInflater.inflate(LayoutInflater.java:534) at android.view.LayoutInflater.inflate(LayoutInflater.java:481) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) at com.example.project.CustomCalendarActivity.onCreate(CustomCalendarActivity.java:15) at android.app.Activity.performCreate(Activity.java:7802) at android.app.Activity.performCreate(Activity.java:7791) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.example.project.CustomCalendarView.SetUpCalendar(CustomCalendarView.java:149) at com.example.project.CustomCalendarView.(CustomCalendarView.java:56) ... 28 more I/Process: Sending signal. PID: 29100 SIG: 9
Java code
package com.example.project;
import android.app.Activity; import android.os.Bundle;
import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity;
public class CustomCalendarActivity extends AppCompatActivity { CustomCalendarView customCalendarView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calendar_layout_activity);
customCalendarView=(CustomCalendarView)findViewById(R.id.custom_calendar_view);
}
}
xml file
<?xml version="1.0" encoding="utf-8"?>
<com.example.project.CustomCalendarView
android:id="@+id/custom_calendar_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"></com.example.project.CustomCalendarView>
Did you write a custom view called Custom Calendar View properly?
© 2024 OneMinuteCode. All rights reserved.