OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Android Studio Error uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details

  • Thread starter Thread starter Pillowonkaa
  • Start date Start date
P

Pillowonkaa

Guest
This is my code, and when i run the app it shows this error in my MainActivity.java

Note: Recompile with -Xlint:deprecation for details.

I try to fix buy Alt+Enter and when it success the app i built got crash

Code:
package com.first.moviebay.Activities;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.CompositePageTransformer;
import androidx.viewpager2.widget.MarginPageTransformer;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.first.moviebay.Adapters.SlidersAdapter;
import com.first.moviebay.Domains.SliderItems;
import com.first.moviebay.databinding.ActivityMainBinding;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    ActivityMainBinding binding;
    private FirebaseDatabase database;
    private Handler sliderHandler =new Handler();
    private Runnable sliderRunnable=new Runnable() {
        @Override
        public void run() {
            binding.viewPager2.setCurrentItem(binding.viewPager2.getCurrentItem()+1);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding=ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        database=FirebaseDatabase.getInstance();

        Window w=getWindow();
        w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

        initBanner();
    }

    private void initBanner() {
        DatabaseReference myRef=database.getReference("Banners");
        binding.progressBarBanner.setVisibility(View.VISIBLE);
        ArrayList<SliderItems> items=new ArrayList<>();
        myRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                if (snapshot.exists()){
                    for (DataSnapshot issue:snapshot.getChildren()){
                        items.add(issue.getValue(SliderItems.class));
                    }
                    banners(items);
                    binding.progressBarBanner.setVisibility(View.GONE);
                }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError error) {

            }
        });
    }
    private void banners(ArrayList<SliderItems> items){
        binding.viewPager2.setAdapter(new SlidersAdapter(items,binding.viewPager2));
        binding.viewPager2.setClipToPadding(false);
        binding.viewPager2.setClipChildren(false);
        binding.viewPager2.setOffscreenPageLimit(3);
        binding.viewPager2.getChildAt(0).setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER);

        CompositePageTransformer compositePageTransformer=new CompositePageTransformer();
        compositePageTransformer.addTransformer(new MarginPageTransformer(40));
        compositePageTransformer.addTransformer(new ViewPager2.PageTransformer() {
            @Override
            public void transformPage(@NonNull View page, float position) {
                float r=1-Math.abs(position);
                page.setScaleY(0.85f+r*0.15f);
            }
        });

        binding.viewPager2.setPageTransformer(compositePageTransformer);
        binding.viewPager2.setCurrentItem(1);
        binding.viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                sliderHandler.removeCallbacks(sliderRunnable);
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        sliderHandler.removeCallbacks(sliderRunnable);
    }

    @Override
    protected void onResume() {
        super.onResume();
        sliderHandler.postDelayed(sliderRunnable, 2000);
    }
}

When i run i got error but the device can run also the app installed but then the app crash/force close

Note: D:\SP 2024\PPB\TubesPB\app\src\main\java\com\first\moviebay\Activities\MainActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: D:\SP 2024\PPB\TubesPB\app\src\main\java\com\first\moviebay\Adapters\SlidersAdapter.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

Thanks for help
<p>This is my code, and when i run the app it shows this error in my MainActivity.java</p>
<blockquote>
<p>Note: Recompile with -Xlint:deprecation for details.</p>
</blockquote>
<p>I try to fix buy Alt+Enter and when it success the app i built got crash</p>
<pre><code>package com.first.moviebay.Activities;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.CompositePageTransformer;
import androidx.viewpager2.widget.MarginPageTransformer;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.first.moviebay.Adapters.SlidersAdapter;
import com.first.moviebay.Domains.SliderItems;
import com.first.moviebay.databinding.ActivityMainBinding;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
ActivityMainBinding binding;
private FirebaseDatabase database;
private Handler sliderHandler =new Handler();
private Runnable sliderRunnable=new Runnable() {
@Override
public void run() {
binding.viewPager2.setCurrentItem(binding.viewPager2.getCurrentItem()+1);
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding=ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

database=FirebaseDatabase.getInstance();

Window w=getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

initBanner();
}

private void initBanner() {
DatabaseReference myRef=database.getReference("Banners");
binding.progressBarBanner.setVisibility(View.VISIBLE);
ArrayList<SliderItems> items=new ArrayList<>();
myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()){
for (DataSnapshot issue:snapshot.getChildren()){
items.add(issue.getValue(SliderItems.class));
}
banners(items);
binding.progressBarBanner.setVisibility(View.GONE);
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}
private void banners(ArrayList<SliderItems> items){
binding.viewPager2.setAdapter(new SlidersAdapter(items,binding.viewPager2));
binding.viewPager2.setClipToPadding(false);
binding.viewPager2.setClipChildren(false);
binding.viewPager2.setOffscreenPageLimit(3);
binding.viewPager2.getChildAt(0).setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER);

CompositePageTransformer compositePageTransformer=new CompositePageTransformer();
compositePageTransformer.addTransformer(new MarginPageTransformer(40));
compositePageTransformer.addTransformer(new ViewPager2.PageTransformer() {
@Override
public void transformPage(@NonNull View page, float position) {
float r=1-Math.abs(position);
page.setScaleY(0.85f+r*0.15f);
}
});

binding.viewPager2.setPageTransformer(compositePageTransformer);
binding.viewPager2.setCurrentItem(1);
binding.viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
sliderHandler.removeCallbacks(sliderRunnable);
}
});
}

@Override
protected void onPause() {
super.onPause();
sliderHandler.removeCallbacks(sliderRunnable);
}

@Override
protected void onResume() {
super.onResume();
sliderHandler.postDelayed(sliderRunnable, 2000);
}
}
</code></pre>
<p>When i run i got error but the device can run also the app installed but then the app crash/force close</p>
<blockquote>
<p>Note: D:\SP 2024\PPB\TubesPB\app\src\main\java\com\first\moviebay\Activities\MainActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: D:\SP 2024\PPB\TubesPB\app\src\main\java\com\first\moviebay\Adapters\SlidersAdapter.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.</p>
</blockquote>
<p>Thanks for help</p>
Continue reading...
 

Latest posts

Top