Cannot resolve symbol 'Builder' : package com.example.myapp2.UI.view.fragments; import…
- User
Cannot resolve symbol 'Builder' : package com.example.myapp_2.UI.view.fragments;
import static android.content.Context.MODE_PRIVATE;
import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.Switch; import android.widget.TextView; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.viewpager.widget.ViewPager; import androidx.work.WorkerParameters;
import com.example.myapp_2.List_1.Product; import com.example.myapp_2.List_1.ProductAdapter; import com.example.myapp_2.R; import com.example.myapp_2.SortWorker; import com.example.myapp_2.UI.view.adapters.SliderAdapter;
import java.util.ArrayList; import java.util.List; //import androidx.work.WorkerParameters.Builder; import androidx.core.app.NotificationCompat.Builder;
public class SecondFragment extends Fragment implements View.OnClickListener {
code - Assistant
The issue is likely related to importing two different classes with the same name, "Builder". Check the import statements at the top of your code and make sure that you are importing the correct Builder class.
Instead of importing both
androidx.core.app.NotificationCompat.Builderandandroidx.work.WorkerParameters.BuilderasBuilder, you could rename one of them to avoid conflicts:codeimport androidx.work.WorkerParameters; import androidx.core.app.NotificationCompat; // ... WorkerParameters.Builder workerBuilder = new WorkerParameters.Builder(); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getContext().getApplicationContext(), CHANNEL_ID);Here, we use the full package name for each class to differentiate between them, and give each Builder object a specific name.
- User
// создаем объект SortWorker и вызываем метод сортировки SortWorker sortWorker = new SortWorker(getActivity(), new WorkerParameters.Builder().build(), productAdapter); sortWorker.sortProducts();
code// устанавливаем адаптер для отображения списка товаров RecyclerView recyclerView = v.findViewById(R.id.recycler_view_products); recyclerView.setAdapter(productAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); Исправь ощибки - Assistant
The code to call the
sortProductsmethod ofSortWorkershould come after setting up the RecyclerView adapter and layout manager, since those need to be initialized first. Here's the corrected code:code// устанавливаем адаптер для отображения списка товаров RecyclerView recyclerView = v.findViewById(R.id.recycler_view_products); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); productAdapter = new ProductAdapter(getContext(), products); recyclerView.setAdapter(productAdapter); // создаем объект SortWorker и вызываем метод сортировки SortWorker sortWorker = new SortWorker(getActivity(), new WorkerParameters.Builder().build(), productAdapter); sortWorker.sortProducts();This creates the RecyclerView and sets up the adapter and layout manager