Здравствуйте, в Play Store Locks я пропускаю следующую ошибку и не могу устранить ошибку. Чем больше загрузок приложений, тем больше пользователей увеличивается с этой ошибкой, я бы хотел, чтобы они посмотрели, чтомой код может не работать
Ошибка:
java.lang.RuntimeException:
at android.os.AsyncTask$3.done (AsyncTask.java:304)
at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:355)
at java.util.concurrent.FutureTask.setException (FutureTask.java:222)
at java.util.concurrent.FutureTask.run (FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run (AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:587)
at java.lang.Thread.run (Thread.java:818)
Caused by: java.lang.NullPointerException:
at android.graphics.Bitmap.createScaledBitmap (Bitmap.java:603)
at com.aaadesigner.guideffwall.infowall$SetWallpaperTask.doInBackground (infowall.java:166)
at com.aaadesigner.guideffwall.infowall$SetWallpaperTask.doInBackground (infowall.java:139)
at android.os.AsyncTask$2.call (AsyncTask.java:292)
at java.util.concurrent.FutureTask.run (FutureTask.java:237)
Здесь я оставляю код Java, который я использую:
import android.app.ProgressDialog;
import android.app.WallpaperManager;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.squareup.picasso.Picasso;
import java.io.IOException;
import java.util.Objects;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class infowall extends AppCompatActivity {
private AdView mAdView;
private RequestOptions options;
LinearLayout img;
public ProgressDialog progressDialog;
private LinearLayout layoutAnimado;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_infowall);
layoutAnimado = findViewById(R.id.animado);
final ProgressBar progressBar = findViewById(R.id.progress);
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Button btnSetWallpaper = findViewById(R.id.btn);
btnSetWallpaper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new SetWallpaperTask().execute();
}
});
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
this.options = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
String image_url = Objects.requireNonNull(getIntent().getExtras()).getString("img2");
String fuente = getIntent().getExtras().getString("fuente");
TextView tv_fuente = findViewById(R.id.fuente);
tv_fuente.setText(fuente);
img = findViewById(R.id.thumbnail2);
Glide.with(this)
.load(image_url)
.apply(options)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
})
.error(
Glide
.with(this)
.load(R.drawable.error)
)
.into(new CustomTarget<Drawable>() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
img.setBackground(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
TextView txtclose = findViewById(R.id.txtclose);
txtclose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT) ** ----> (infowall.java:139)**
public class SetWallpaperTask extends AsyncTask<String, Void, Bitmap> {
String image_url = Objects.requireNonNull(getIntent().getExtras()).getString("img2");
@Override
protected Bitmap doInBackground(String... params) {
Bitmap result= null;
try {
result = Picasso.get()
.load(image_url)
.get();
} catch (IOException e) {
e.printStackTrace();
}
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels;
int width = metrics.widthPixels;
Log.e("Width", "" + width);
Log.e("height", "" + height);
assert result != null;
Bitmap bitmap = Bitmap.createScaledBitmap(result, width, height, true); **---> (infowall.java:166)**
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
wallpaperManager.setWallpaperOffsetSteps(1, 1);
wallpaperManager.suggestDesiredDimensions(width, height);
try {
wallpaperManager.setBitmap(bitmap);
} catch (IOException ex) {
ex.printStackTrace();
}
return result;
}
@Override
protected void onPreExecute () {
super.onPreExecute();
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
progressDialog = new ProgressDialog(infowall.this);
progressDialog.setMessage(getString(R.string.proceso));
progressDialog.setCancelable(true);
progressDialog.show();
}
@Override
protected void onPostExecute (Bitmap result) {
super.onPostExecute(result);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getBaseContext());
try {
wallpaperManager.setBitmap(result);
progressDialog.dismiss();
Toast toast3 = new Toast(getApplicationContext());
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.lytLayout));
TextView txtMsg = layout.findViewById(R.id.txtMensaje);
txtMsg.setText(getResources().getString(R.string.wallyes));
toast3.setDuration(Toast.LENGTH_LONG);
toast3.setGravity(Gravity.CENTER, 20, 20);
toast3.setView(layout);
toast3.show();
//Toast.makeText(getApplicationContext(), getResources().getString(R.string.wallyes), Toast.LENGTH_SHORT).show();
finish();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public void mostrar(View button)
{
if (layoutAnimado.getVisibility() == View.GONE)
{
animar(true);
layoutAnimado.setVisibility(View.VISIBLE);
}
}
public void ocultar(View button)
{
if (layoutAnimado.getVisibility() == View.VISIBLE)
{
animar(false);
layoutAnimado.setVisibility(View.GONE);
}
}
private void animar(boolean mostrar)
{
AnimationSet set = new AnimationSet(true);
Animation animation;
if (mostrar)
{
//desde la esquina inferior derecha a la superior izquierda
animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
}
else
{ //desde la esquina superior izquierda a la esquina inferior derecha
animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f);
}
//duración en milisegundos
animation.setDuration(500);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.25f);
layoutAnimado.setLayoutAnimation(controller);
layoutAnimado.startAnimation(animation);
}
}
Заранее спасибоза всю помощь, которую вы мне оказываете