Im having an issue with a click listener for a submit modal submit button.
This is the error.
FATAL EXCEPTION: main
Process: com.kuryetaxi.omerkaptan.kuryetaxi, PID: 6564
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.button.MaterialButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
I have a reasonable understanding of what a null pointer exception is and I have search thoroughly for an issue similar to mine. I have tried to reformat the click listener in several ways, made sure I have the correct view ID etc.
fragment code
View view;
private RecyclerView siparislerrecyclerview;
private SiparisAdapter siparisAdapter;
private List<SiparisModel> siparisList;
private ChangeFragments changeFragments;
private String siparis_id,kurye_id;
private GetSharedPreferences getSharedPreferences;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_kurye_siparis, container, false);
tanimla();
gerek();
getSip("0");
return view;
}
public void tanimla()
{
siparisList = new ArrayList<>();
siparislerrecyclerview = view.findViewById(R.id.siparislerrecyclerview);
RecyclerView.LayoutManager mng = new GridLayoutManager(getContext(),1);
siparislerrecyclerview.setLayoutManager(mng);
changeFragments = new ChangeFragments(getContext());
getSharedPreferences = new GetSharedPreferences(getActivity());
siparis_id=getSharedPreferences.getSession().getString("id",null);
}
public void getSip(String kur_durum)
{
Call<List<SiparisModel>> req = getInstance().getSip(kur_durum);
req.enqueue(new Callback<List<SiparisModel>>() {
@Override
public void onResponse(Call<List<SiparisModel>> call, Response<List<SiparisModel>> response) {
Log.i("listem",response.body().toString());
if (response.body().get(0).isTf())
{
siparisList = response.body();
siparisAdapter = new SiparisAdapter(siparisList,getContext());
siparislerrecyclerview.setAdapter(siparisAdapter);
}
else
{
Toast.makeText(getContext(),"FİRMA SİPARİSİ BULUNMAMAKTADIR",Toast.LENGTH_LONG).show();
changeFragments.change(new HomeFragment());
}
}
@Override
public void onFailure(Call<List<SiparisModel>> call, Throwable t) {
Toast.makeText(getContext(), Warnings.internetProblemText,Toast.LENGTH_LONG).show();
}
});
}
public void gerek()
{
MaterialButton ekle = (MaterialButton)view.findViewById(R.id.ekleButton);
ekle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
siparisAl(siparis_id);
}
});
}
public void siparisAl(String siparis_id)
{
Call<SiparisAlModel> req = ManagerAll.getInstance().siparisAl(siparis_id);
req.enqueue(new Callback<SiparisAlModel>() {
@Override
public void onResponse(Call<SiparisAlModel> call, Response<SiparisAlModel> response) {
Log.i("hatas",response.body().toString());
Toast.makeText(getContext(),response.body().getText(),Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Call<SiparisAlModel> call, Throwable t) {
Toast.makeText(getContext(),Warnings.internetProblemText,Toast.LENGTH_LONG).show();
}
});
}
layout.xml code
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/siparisdetaylayout">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
card_view:cardBackgroundColor="#f8b518"
android:layout_height="wrap_content"
android:layout_margin="5dp"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:clickable="true"
android:id="@+id/siparisdetaylayout"
android:layout_margin="6dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_margin="15dp"
android:id="@+id/logo"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
<TextView
android:layout_gravity="left"
android:layout_width="125dp"
android:id="@+id/firmatext"
android:textStyle="bold"
android:textSize="17dp"
android:gravity="left"
android:textColor="#FF000000"
android:layout_height="wrap_content" />
<TextView
android:layout_gravity="left"
android:id="@+id/tarihtext"
android:layout_width="125dp"
android:textStyle="bold"
android:textSize="17dp"
android:gravity="left"
android:textColor="#FF000000"
android:layout_height="wrap_content" />
<TextView
android:layout_gravity="left"
android:id="@+id/saattext"
android:layout_width="125dp"
android:textStyle="bold"
android:textSize="17dp"
android:gravity="left"
android:textColor="#FF000000"
android:layout_height="wrap_content" />
<android.support.design.button.MaterialButton
android:id="@+id/ekleButton"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:text="Ekle"
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>