رونمایی از پخته‌ترین و کاربردی‌ترین محصولات آموزشی سون‌لرن با کلی آفرهای ویژه🔥
۰ ثانیه
۰ دقیقه
۰ ساعت
۱ سعید امیراحمدی
ارور تولبار هنگام ران کردن
جامعه جاوا (اندروید) ایجاد شده در ۱۲ شهریور ۱۴۰۲

در کد نوشته شده خطایی نمیبینم به نظرم خطا نا مربوط هست ولی اجازه بیلد شدن نمیده

--------------------

ارور

error: incompatible types: android.widget.Toolbar cannot be converted to androidx.appcompat.widget.Toolbar

    setSupportActionBar(toolbar);

              ^

---------------------------------------------

کلاس add new student

public class AddNewStudentActivity extends AppCompatActivity {
    private static final String TAG = "AddNewStudentActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_new_student_activity);
        Toolbar toolbar= findViewById(R.id.toolbar_addnewstudent);
        setSupportActionBar(toolbar);

-------------------------------------------

add_new_student_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:titleTextColor="@color/white"
            android:id="@+id/toolbar_addnewstudent"/>
    com.google.android.material.appbar.AppBarLayout>

سلام وقت بخیر

شما در فایل xml خود از androidx.appcompat.widget.Toolbar استفاده کرده اید در حالیکه در فایل جاوایی خود این تول بار را android.widget.Toolbar ایمپورت کرده اید. لطفا چک کنید که تول بار‌ها هر دو از یک پکیج باشند تا مشکل حل شود.

بهترین پاسخ
سعیده جمالی ۱۳ شهریور ۱۴۰۲، ۰۶:۵۵