BUG, activity does not load fragment with firebase data [duplicate] - java

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Avoiding NullPointerException in Java
(66 answers)
Closed 8 months ago.
my application so far is like this: in ActivityHome, it opens the Fragments using a "FragmentContainerView", my FragmentHome loads the firebase videos in a ViewPage2, using the design of an xml file
The problem is that after finishing the class files, the application does not run and presents the error in onCreate(Home.java), I could not solve the error or find the problem
Could someone point out how to solve this BUG?
layout/Activity_Home:
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Home">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="androidx.navigation.fragment.NavHostFragment"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#+id/nav_inferior"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/nav_main"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_add_24"
app:maxImageSize="50dp"
android:backgroundTint="#3f3f3f"
app:borderWidth="0dp"
app:layout_anchor="#id/nav_inferior"
android:contentDescription="#string/nav_post" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/nav_inferior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:fabCradleRoundedCornerRadius="20dp"
app:fabCradleMargin="10dp"
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav_inferior"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
app:menu="#menu/menu_inferior"
android:layout_marginEnd="20dp"
app:itemIconTint="#color/nav_item_bg"
app:itemTextColor="#color/nav_item_bg"
/>
</com.google.android.material.bottomappbar.BottomAppBar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Home.java
public class Home extends AppCompatActivity {
BottomNavigationView bottomNavigationView;
ActivityHomeBinding binding;
private NavHostFragment navHostFragment;
private NavController navController;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
binding = ActivityHomeBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
IniciarComponentes();
IniciarNavegacao();
IniciarBadge();
}
private void IniciarNavegacao(){
navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
navController = navHostFragment.getNavController();
NavigationUI.setupWithNavController(binding.bottomNavInferior, navController);
navController.addOnDestinationChangedListener((navController, navDestination, bundle) -> {
if (navDestination.getId() == R.id.nav_painel){
BadgeDrawable badgeDrawable = binding.bottomNavInferior.getBadge(R.id.bottom_nav_inferior);
if (badgeDrawable != null){
badgeDrawable.setVisible(false);
badgeDrawable.clearNumber();
}
}
});
}
private void IniciarBadge(){
BadgeDrawable badge = binding.bottomNavInferior.getOrCreateBadge(R.id.nav_painel);
badge.setVisible(true);
badge.setNumber(99);
badge.setBackgroundColor(ContextCompat.getColor(this,R.color.colorError));
badge.setBadgeTextColor(ContextCompat.getColor(this, com.denzcoskun.imageslider.R.color.text_shadow_white));
}
private void IniciarComponentes(){
bottomNavigationView = findViewById(R.id.bottom_nav_inferior);
bottomNavigationView.setBackground(null);
}
}
layout/FragmentHome
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.HomeFragment">
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/homeVideos"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</FrameLayout>
fragmente/FragmentHome.java
public class HomeFragment extends Fragment {
private FragmentHomeBinding binding;
VideosConvert videosConvert;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ViewPager2 viewPager2 = binding.homeVideos;
FirebaseRecyclerOptions<VideosDados> options =
new FirebaseRecyclerOptions.Builder<VideosDados>()
.setQuery(FirebaseDatabase.getInstance().getReference().child("Videos"), VideosDados.class)
.build();
videosConvert = new VideosConvert(options);
viewPager2.setAdapter(videosConvert);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
binding = FragmentHomeBinding.inflate(inflater,container, false);
View root = binding.getRoot();
return root;
}
#Override
public void onStart() {
super.onStart();
videosConvert.startListening();
}
#Override
public void onStop() {
super.onStop();
videosConvert.stopListening();
}
}
layout/videoDesign
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">
<VideoView
android:id="#+id/videoView"
android:layout_width="0dp"
android:layout_height="0dp"
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="1.0" />
<ProgressBar
android:id="#+id/videoProgressBar"
android:layout_width="30dp"
android:layout_height="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.888">
<TextView
android:id="#+id/textoTituloVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="6.00sp"
android:layout_marginBottom="7.80sp"
android:fontFamily="sans-serif-medium"
android:textColor="#android:color/white"
android:paddingStart="5dp"
android:paddingTop="5dp"
android:paddingEnd="5dp"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="15"
android:text="Título"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textoDescricaoVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="7.80sp"
android:layout_marginEnd="46.8dp"
android:layout_marginBottom="20.80dp"
android:textColor="#android:color/white"
android:fontFamily="#font/calibri"
android:paddingStart="5dp"
android:paddingTop="5dp"
android:paddingEnd="5dp"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="15"
android:text="Descrição do vídeo"
android:textSize="16sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
VideoConvert.java
public class VideosConvert extends FirebaseRecyclerAdapter<VideosDados, VideosConvert.myviewholder> {
public VideosConvert(#NonNull FirebaseRecyclerOptions<VideosDados> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull myviewholder holder, int position, #NonNull VideosDados model) {
holder.setdata(model);
}
#NonNull
#Override
public myviewholder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.video_design,parent,false);
return new myviewholder(view);
}
public class myviewholder extends RecyclerView.ViewHolder {
VideoView videoView;
TextView titolo,desc;
ProgressBar progressBar;
public myviewholder(#NonNull View itemView) {
super(itemView);
videoView=(VideoView)itemView.findViewById(R.id.videoView);
titolo=(TextView)itemView.findViewById(R.id.textoTituloVideo);
desc=(TextView)itemView.findViewById(R.id.textoDescricaoVideo);
progressBar=(ProgressBar)itemView.findViewById(R.id.videoProgressBar);
}
public void setdata(VideosDados model) {
videoView.setVideoPath(model.getUrl());
titolo.setText(model.getTitle());
desc.setText(model.getDesc());
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
progressBar.setVisibility(View.GONE);
mp.start();
}
});
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mp.start();
}
});
}
}
}
VideoDados.java
public class VideosDados {
String desc,title,url;
public VideosDados(String desc, String title, String url) {
this.desc = desc;
this.title = title;
this.url = url;
}
VideosDados() {
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
after hours of failing to resolve, it seems impossible to resolve.
thanks for the time and help
Debug
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.meinlowe.souldiabah, PID: 30521
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.meinlowe.souldiabah/com.meinlowe.souldiabah.Home}: android.view.InflateException: Binary XML file line #11 in com.meinlowe.souldiabah:layout/activity_home: Binary XML file line #11 in com.meinlowe.souldiabah:layout/activity_home: Error inflating class androidx.fragment.app.FragmentContainerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4035)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4201)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
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:2438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: android.view.InflateException: Binary XML file line #11 in com.meinlowe.souldiabah:layout/activity_home: Binary XML file line #11 in com.meinlowe.souldiabah:layout/activity_home: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #11 in com.meinlowe.souldiabah:layout/activity_home: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: java.lang.NullPointerException: Attempt to read from field 'androidx.viewpager2.widget.ViewPager2 com.meinlowe.souldiabah.databinding.FragmentHomeBinding.homeVideos' on a null object reference
at com.meinlowe.souldiabah.fragments.HomeFragment.onCreate(HomeFragment.java:27)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2981)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:474)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:257)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1764)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1701)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2849)
at androidx.fragment.app.FragmentManager.dispatchCreate(FragmentManager.java:2773)
at androidx.fragment.app.Fragment.onCreate(Fragment.java:1913)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.kt:169)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2981)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:474)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:257)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1764)
at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1670)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:323)
at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.kt:158)
at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:53)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:295)
E/AndroidRuntime: at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:274)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1073)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at com.meinlowe.souldiabah.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:56)
at com.meinlowe.souldiabah.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:50)
at com.meinlowe.souldiabah.Home.onCreate(Home.java:28)
at android.app.Activity.performCreate(Activity.java:8290)
at android.app.Activity.performCreate(Activity.java:8270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4009)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4201)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
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:2438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Related

how to get data from mysql database into recycler view?

I am making an app that let users create meetings and I would like the details of the meeting (eg name, type, location) in a recycler view.I ran the php code by itself and was able to get the values from the database.
Currently, I am getting an error of
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at in recyclerviewAdapter
holder.Name.setText(users.getName());
holder.Type.setText(users.getType());
holder.Location.setText(users.getLocation());
which is linked to
public class Users {
private String name,type,location;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
}
recyclerviewAdapter
public class UserAdapter extends RecyclerView.Adapter<UserAdapter.UserHolder>{
Context context;
List<Users> usersList;
public UserAdapter(Context context, List<Users> usersList) {
this.context = context;
this.usersList = usersList;
}
#NonNull
#Override
public UserHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View userLayout= LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_main2,parent,false);
return new UserHolder(userLayout);
}
#Override
public void onBindViewHolder(#NonNull UserHolder holder, int position) {
Users users=usersList.get(position);
holder.Name.setText(users.getName());
holder.Type.setText(users.getType());
holder.Location.setText(users.getLocation());
}
#Override
public int getItemCount() {
return usersList.size();
}
public class UserHolder extends RecyclerView.ViewHolder{
TextView Name,Type,Location;
public UserHolder(#NonNull View itemView){
super(itemView);
Name=itemView.findViewById(R.id.textTitle);
Type=itemView.findViewById(R.id.textType);
Location=itemView.findViewById(R.id.textLocation);
}
}
}
main activity code
public class MainActivity2 extends AppCompatActivity {
private static final String URL = "http://10.0.2.2/mad/activitydisplay.php";
RecyclerView recyclerView;
UserAdapter userAdapter;
List<Users> usersList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
recyclerView = findViewById(R.id.recylcerList);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
usersList=new ArrayList<>();
LoadAllUser();
}
private void LoadAllUser() {
JsonArrayRequest request =new JsonArrayRequest(URL, new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray array) {
for (int i=0;i<array.length();i++){
try {
JSONObject object=array.getJSONObject(i);
String name=object.getString("eventname").trim();
String type=object.getString("type").trim();
String location=object.getString("location").trim();
Users user= new Users();
user.setName(name);
user.setType(type);
user.setLocation(location);
usersList.add(user);
} catch (JSONException e) {
e.printStackTrace();
}
}
userAdapter=new UserAdapter(MainActivity2.this,usersList);
recyclerView.setAdapter(userAdapter);
}
},new Response.ErrorListener(){
#Override
public void onErrorResponse(VolleyError error){
Toast.makeText(MainActivity2.this, error.toString(), Toast.LENGTH_SHORT).show();
}
});
RequestQueue requestQueue=Volley.newRequestQueue(MainActivity2.this);
requestQueue.add((request));
}
}
php code to get data from table
$sql="SELECT * FROM `activitytable` ";
$result=mysqli_query($conn,$sql);
$user=array();
while($row = mysqli_fetch_assoc($result)){
$index['eventname']=$row['eventname'];
$index['type']=$row['type'];
$index['location']=$row['location'];
array_push($user, $index);
}
echo json_encode($user);
activity_main2.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"
tools:context=".MainActivity2">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recylcerList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
activity_list resource file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<TextView
style="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title:"
android:textColor="#color/black"
android:textSize="24dp" />
<TextView
android:id="#+id/textTitle"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<TextView
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type:"
android:textColor="#color/black"
android:textSize="24dp" />
<TextView
android:id="#+id/textType"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<TextView
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location:"
android:textColor="#color/black"
android:textSize="24dp" />
<TextView
android:id="#+id/textLocation"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="24dp" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
instead of
public UserHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View userLayout= LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_main2,parent,false);
return new UserHolder(userLayout);
}
use this
public UserHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View userLayout= LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_list ,parent,false);
return new UserHolder(userLayout);
}
because activity_main2 doesn't contain R.id.textTitle,R.id.textType,R.id.textLocation
check your xml(R.layout.activity_main2) looks like id of your view are from another layout

How can i solve this error in android studio? java.lang.IllegalStateException: Required view 'recycler_food_list'

I'm new to android studio and i'm not sure what was going on with it. How can I solve this error?
In the logcat, it mentioned that I required a view for recycler_food_list which apparently I had already coded into the foodlistfragment.java.
Logcat
2021-06-15 11:11:57.189 5164-5164/com.android.ridefun E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.ridefun, PID: 5164
java.lang.IllegalStateException: Required view 'recycler_food_list' with ID 2131231048 for field 'recycler_food_list' was not found. If this view is optional add '#Nullable' (fields) or '#Optional' (methods) annotation.
at butterknife.internal.Utils.findRequiredView(Utils.java:84)
at butterknife.internal.Utils.findRequiredViewAsType(Utils.java:96)
at com.android.ridefun.ui.foodlist.FoodListFragment_ViewBinding.<init>(FoodListFragment_ViewBinding.java:21)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at butterknife.ButterKnife.bind(ButterKnife.java:170)
at com.android.ridefun.ui.foodlist.FoodListFragment.onCreateView(FoodListFragment.java:44)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2106)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
fragment_food_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_food_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
layout_food_item
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginBottom="8dp"
app:cardCornerRadius="0dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/img_food_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#AA333639"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="10">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/txt_food_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name of food"
android:textSize="20sp"
android:textColor="#color/white"/>
<TextView
android:id="#+id/txt_food_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="$0"
android:textSize="20sp"
android:textColor="#color/white"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:id="#+id/img_fav"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_baseline_favorite_border_24"
app:tint="#color/white"/>
<ImageView
android:id="#+id/img_quick_cart"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_baseline_shopping_cart_24"
app:tint="#color/white"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
FoodListFragment.java
public class FoodListFragment extends Fragment {
private FoodListViewModel sendViewModel;
Unbinder unbinder ;
#BindView(R.id.recycler_food_list)
RecyclerView recycler_food_list;
LayoutAnimationController layoutAnimationController;
MyFoodListAdapter adapter;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
sendViewModel =
new ViewModelProvider(this).get(FoodListViewModel.class);
View root = inflater.inflate(R.layout.fragment_menu, container, false);
unbinder = ButterKnife.bind(this,root);
initViews();
sendViewModel.getMutableLiveDataFoodList().observe(getViewLifecycleOwner(), foodModels -> {
adapter = new MyFoodListAdapter(getContext(),foodModels);
recycler_food_list.setAdapter(adapter);
recycler_food_list.setLayoutAnimation(layoutAnimationController);
});
return root;
}
private void initViews() {
recycler_food_list.setHasFixedSize(true);
recycler_food_list.setLayoutManager(new LinearLayoutManager(getContext()));
layoutAnimationController = AnimationUtils.loadLayoutAnimation(getContext(),R.anim.layout_item_from_left);
}
MyFoodListAdapter
public class MyFoodListAdapter extends RecyclerView.Adapter<MyFoodListAdapter.MyViewHolder> {
private Context context;
private List<FoodModel> foodModelList;
public MyFoodListAdapter(Context context, List<FoodModel> foodModelList) {
this.context = context;
this.foodModelList = foodModelList;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
return new MyViewHolder(LayoutInflater.from(context)
.inflate(R.layout.layout_food_item,parent,false));
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
Glide.with(context).load(foodModelList.get(position).getImage()).into(holder.img_food_image);
holder.txt_food_price.setText(new StringBuilder("$")
.append(foodModelList.get(position).getPrice()));
holder.txt_food_name.setText(new StringBuilder("")
.append(foodModelList.get(position).getName()));
}
#Override
public int getItemCount() {
return foodModelList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
private Unbinder unbinder;
#BindView(R.id.txt_food_name)
TextView txt_food_name;
#BindView(R.id.txt_food_price)
TextView txt_food_price;
#BindView(R.id.img_food_image)
ImageView img_food_image;
#BindView(R.id.img_fav)
ImageView img_fav;
#BindView(R.id.img_quick_cart)
ImageView img_cart;
public MyViewHolder(#NonNull View itemView) {
super(itemView);
unbinder = ButterKnife.bind(this,itemView);
}
}
You're doing inflater.inflate(R.layout.fragment_menu, container, false);, not inflating your R.layout.fragment_food_list. You'll need to inflate the right layout to find your Recycler view.

Android View InflateExeption showing up when trying to start an app

I'm new to android development, and I'm having issues with my app crashing when I'm trying to start it
This is the error message:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cybermath/com.example.cybermath.modules.MainActivity}: android.view.InflateException: Binary XML file line #25: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
And this is the XML file for the data within recycler viewer:
'''
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:gravity="center_vertical"
android:background="#color/colorPrimaryDark"
>
<TextView
android:id="#+id/account_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="70"
android:background="#color/colorPrimary"
android:lines="1"
android:padding="10dp"
android:text="#string/app_name"
android:textColor="#color/colorText" >
</TextView>
<TextView
android:id="#+id/account_progress"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="20"
android:background="#color/colorPrimary"
android:text="Enter"
android:textSize="12sp"
android:textColor="#color/colorText"
>
</TextView>
'''
This is the XML for the MainActivity:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="416dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/informationView"
android:id="#+id/recyclerView">
</androidx.recyclerview.widget.RecyclerView>
<!--<TextView
android:id="#+id/informationView"
android:layout_width="408dp"
android:layout_height="50dp"
android:foregroundTint="#00050000"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:text="Choose an account"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.333"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</TextView>-->
</androidx.constraintlayout.widget.ConstraintLayout>
And here is the code for the MainActivity:
'''
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
// UI
private RecyclerView mRecyclerView;
// Variables
#NonNull
private ArrayList<Account> mAccounts = new ArrayList<>();
private AccountsRecyclerAdapter mAccountsRecyclerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_account_list);
mRecyclerView = findViewById(R.id.recyclerView);
initRecyclerView();
insertFakeAccounts();
}
private void insertFakeAccounts(){
for(int i = 0; i < 1000; i++){
Account account = new Account();
account.setName("title #" + i);
mAccounts.add(account);
}
mAccountsRecyclerAdapter.notifyDataSetChanged();
}
private void initRecyclerView(){
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(linearLayoutManager);
mAccountsRecyclerAdapter = new AccountsRecyclerAdapter(mAccounts);
mRecyclerView.setAdapter(mAccountsRecyclerAdapter);
}
'''
And my adapter public class AccountsRecyclerAdapter extends
RecyclerView.Adapter<AccountsRecyclerAdapter.ViewHolder> {
private ArrayList<Account> mAccounts = new ArrayList<>();
public AccountsRecyclerAdapter(ArrayList<Account> accounts) {
this.mAccounts = accounts;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int i) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_account_list, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull AccountsRecyclerAdapter.ViewHolder viewHolder, int i) {
viewHolder.name.setText(mAccounts.get(i).getName());
}
#Override
public int getItemCount() {
return mAccounts.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView name;
public ViewHolder(#NonNull View itemView) {
super(itemView);
name = itemView.findViewById(R.id.account_name);
}
}
Some if the thing are not as per requirement may cause an exception. Check for condition as
if(yourValue !=null && yourValue.equals("desired value"){
//do your stuff
}

How to fix TextView being rendered blank on new Activity

I'm trying to start another activity after clicking on a CardView inside a RecyclerView. The new activity renders after the click on any of the items inside the RecyclerView (It does the transition and changes the title TextView), but it does not show any of the TextView's inside the CardView on the layout.
The OnClick method is being set as an interface and being implemented in the first Activity.
Here is my first activity. I'm loading the data here from a SQLite database, but it's not relevant for the question to show the code from it.
public class MainActivity extends AppCompatActivity implements RecipeAdapterMain.OnCardListener {
private TextView tv;
ArrayList<RecipeObject> recipes = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView rv = findViewById(R.id.recipeListMain);
LinearLayoutManager llm = new LinearLayoutManager(this);
rv.setLayoutManager(llm);
RecipeAdapterMain adapter = new RecipeAdapterMain(recipes, this);
rv.setAdapter(adapter);
tv = findViewById(R.id.title);
}
#Override
public void onCardClick(int position) {
Intent intent = new Intent(this, RecipeActivity.class);
startActivity(intent);
}
}
This is my Adapter.
public class RecipeAdapterMain extends RecyclerView.Adapter<RecipeAdapterMain.RecipeListViewHolder> {
RecyclerView mRecyclerView;
ArrayList<RecipeObject> recipeList;
private OnCardListener mOnCardListener;
public RecipeAdapterMain(Context context, ArrayList<RecipeObject> recipeList, OnCardListener onCardListener) {
this.mOnCardListener = onCardListener;
this.recipeList = recipeList;
}
#Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
mRecyclerView = recyclerView;
super.onAttachedToRecyclerView(recyclerView);
}
#Override
public RecipeListViewHolder onCreateViewHolder(ViewGroup parent, int i) {
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_recipe_main, parent, false);
RecipeListViewHolder rcv = new RecipeListViewHolder(layoutView, mOnCardListener);
return rcv;
}
#Override
public void onBindViewHolder(#NonNull RecipeListViewHolder holder, int position) {
holder.mName.setText(recipeList.get(position).getName());
}
#Override
public int getItemCount(){
return recipeList.size();
}
public class RecipeListViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView mName;
OnCardListener onCardListener;
public RecipeListViewHolder(final View view, OnCardListener onCardListener) {
super(view);
mName = view.findViewById(R.id.textViewTitle);
this.onCardListener = onCardListener;
view.setOnClickListener(this);
}
#Override
public void onClick(View v) {
onCardListener.onCardClick(getAdapterPosition());
}
}
public interface OnCardListener {
void onCardClick(int position);
}
}
My second activity:
public class RecipeActivity extends AppCompatActivity {
#Override
public void onCreate(#Nullable Bundle savedInstanceState, #Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.layout_recipe);
}
}
This is the layout from the second activity. (layout_recipe):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a test"
android:textColor="#1A1A1A"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewIngr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a test"
android:textColor="#1A1A1A"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewDire"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a test"
android:textColor="#1A1A1A"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
And this is the layout from the first activity (activity_main):
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recipeListMain"
android:scrollbars="vertical">
</androidx.recyclerview.widget.RecyclerView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="#color/colorAccent"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:layout_marginBottom="16dp"
android:contentDescription="#string/submit"
android:src="#drawable/ic_add_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:onClick="openActivityCreate"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
From clicking in a Card on the MainActivity, I expected to render the second activity with it's TextViews (This is a test), but it's rendering a blank page instead.
try removing #Nullable PersistableBundle persistentState from onCreate on your second activity

RecyclerView NullPointerException

in the moment Iam playing arround with the RecyclerView. The whole time I get some NullPointer Exceptions but I can't find why.
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.lueth.erik.birthdays/de.lueth.erik.birthdays.TodaysBirthdays.TodaysBirthdaysActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setHasFixedSize(boolean)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5349)
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:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setHasFixedSize(boolean)' on a null object reference
at de.lueth.erik.birthdays.TodaysBirthdays.TodaysBirthdaysActivity.onCreate(TodaysBirthdaysActivity.java:23)
at android.app.Activity.performCreate(Activity.java:6020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2284)...
Here is my TodaysBirthdaysActivity.class
The onCreate part looks like that one that Google is showing in their RecyclerView tutorial.
public class TodaysBirthdaysActivity extends Activity{
private RecyclerView recList;
private RecyclerView.Adapter adp;
private RecyclerView.LayoutManager llm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_birthday_list);
recList = (RecyclerView) findViewById(R.id.cardList);
recList.setHasFixedSize(true);
llm = new LinearLayoutManager(this);
recList.setLayoutManager(llm);
adp = new Adapter(createList(30));
recList.setAdapter(adp);
}
private List<ContactInfo> createList(int size) {
List<ContactInfo> result = new ArrayList<ContactInfo>();
for (int i=1; i <= size; i++) {
ContactInfo ci = new ContactInfo();
ci.name = ContactInfo.NAME_PREFIX + i;
ci.surname = ContactInfo.SURNAME_PREFIX + i;
ci.birthday = ContactInfo.Birthday_PREFIX + i ;
result.add(ci);
}
return result;
}}
Here is my activity_birthday_list.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".TodaysBirthdaysActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent"
/></RelativeLayout>
Here my Adapter.class
public class Adapter extends RecyclerView.Adapter<ContactViewHolder> {
private List<ContactInfo> contactList;
public Adapter(List<ContactInfo> contactList) {
this.contactList = contactList;
}
#Override
public int getItemCount() {
return contactList.size();
}
#Override
public void onBindViewHolder(ContactViewHolder contactViewHolder, int i) {
ContactInfo ci = contactList.get(i);
contactViewHolder.vName.setText(ci.name);
contactViewHolder.vSurname.setText(ci.surname);
contactViewHolder.vBirthday.setText(ci.birthday);
contactViewHolder.vTitle.setText(ci.name + " " + ci.surname);
}
#Override
public ContactViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.
from(viewGroup.getContext()).
inflate(R.layout.contact_card, viewGroup, false);
return new ContactViewHolder(itemView);
}}
here my ContactInfo.java
public class ContactInfo {
protected String name;
protected String surname;
protected String birthday;
protected static final String NAME_PREFIX = "Name_";
protected static final String SURNAME_PREFIX = "Surname_";
protected static final String Birthday_PREFIX = "Birthday_";}
and here my ContentViewHolder.java
public class ContactViewHolder extends RecyclerView.ViewHolder {
protected TextView vName;
protected TextView vSurname;
protected TextView vBirthday;
protected TextView vTitle;
public ContactViewHolder(View v) {
super(v);
vName = (TextView) v.findViewById(R.id.txtName);
vSurname = (TextView) v.findViewById(R.id.txtSurname);
vBirthday = (TextView) v.findViewById(R.id.txtBirthday);
vTitle = (TextView) v.findViewById(R.id.title);
}}
and the xml for the card contact_card.xml
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="#color/cardview_dark_background"
android:text="contact det"
android:gravity="center_vertical"
android:textColor="#android:color/white"
android:textSize="14dp"/>
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:gravity="center_vertical"
android:textSize="10dp"
android:layout_below="#id/title"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"/>
<TextView
android:id="#+id/txtSurname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Surname"
android:gravity="center_vertical"
android:textSize="10dp"
android:layout_below="#id/txtName"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"/>
<TextView
android:id="#+id/txtBirthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Birthday"
android:textSize="10dp"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_marginRight="150dp"
android:layout_alignBaseline="#id/txtName"/>
</RelativeLayout> </android.support.v7.widget.CardView>
It's all in your logcat output:
at de.lueth.erik.birthdays.TodaysBirthdays.TodaysBirthdaysActivity.onCreate(TodaysBirthdaysActivity.java:23)
That line TodaysBirthdaysActivity.java:23 gives you NPE. Which means, your variable recList is null. Why? Most probably, because there is no object with id R.id.cardList inside layout R.layout.activity_birthday_list.

Categories

Resources