Reputation: 27
class is RadarSceen then method ontouch method is crash is null pointer exception and this method use start radar and stop radar.then localRotateAnimation.setDuration(3000L) crash is null pointer exception
public class RadarScreen extends Activity implements View.OnTouchListener {
private static final String APP_TAG = "com.example.ghostsam";
private CountDownTimer countdownHideGhost = null;
private CountDownTimer countdownShowGhost = null;
private DisplayMetrics getDisplay = new DisplayMetrics();
private int getDisplayHeight;
private float getDisplayScale;
private int getDisplayWidth;
private Boolean hideGhosts = Boolean.valueOf(false);
private ImageView ivLogo = null;
private ImageView ivRadar = null;
private ImageView ivRadarGhosts = null;
private ImageView ivSignalButton = null;
private Typeface layoutFontFace;
private Boolean radarRun = Boolean.valueOf(false);
// private RotateAnimation rotateAnimation ;
private RotateAnimation localRotateAnimation;
private boolean settingsGeneralVibrate = true;
private Boolean showGhosts = Boolean.valueOf(false);
private int showGhostsZufallszahl = 0;
private Vibrator vib = null;
public Bitmap drawButton(String paramString1, String paramString2) {
Bitmap localBitmap = Bitmap
.createBitmap(this.getDisplayWidth - (int) (70.0F * this.getDisplayScale),
(int) (52.0F * this.getDisplayScale), Bitmap.Config.ARGB_8888);
Canvas localCanvas = new Canvas(localBitmap);
Paint localPaint = new Paint();
localPaint.setTypeface(this.layoutFontFace);
localPaint.setTextAlign(Paint.Align.CENTER);
localPaint.setAntiAlias(true);
localPaint.setColor(Color.parseColor(paramString2));
localCanvas.drawRoundRect(
new RectF(0.0F, 0.0F, localBitmap.getWidth(), localBitmap.getHeight()), 12.0F,
12.0F, localPaint);
localPaint.setColor(Color.parseColor("#000000"));
localCanvas.drawRoundRect(new RectF(2.0F, 2.0F, -2 + localBitmap.getWidth(),
-2 + localBitmap.getHeight()), 12.0F, 12.0F, localPaint);
localPaint.setColor(Color.parseColor(paramString2));
localPaint.setAlpha(200);
localPaint.setTextSize(32.0F * this.getDisplayScale);
localPaint.setTextScaleX(1.75F);
localPaint.setFakeBoldText(true);
localCanvas.drawText(paramString1, localBitmap.getWidth() / 2,
36.0F * this.getDisplayScale, localPaint);
return localBitmap;
}
public Bitmap drawRadar(Boolean paramBoolean) {
Bitmap localBitmap = Bitmap
.createBitmap(-50 + this.getDisplayWidth, -50 + this.getDisplayWidth,
Bitmap.Config.ARGB_8888);
Canvas localCanvas = new Canvas(localBitmap);
Paint localPaint = new Paint();
int i = (int) ((localBitmap.getWidth() - 10.0F * this.getDisplayScale) / 2.0F
+ 5.0F * this.getDisplayScale);
int j = (int) (i - 5.0F * this.getDisplayScale);
localPaint.setAntiAlias(true);
localPaint.setColor(Color.parseColor("#FFFFFF"));
localPaint.setStyle(Paint.Style.STROKE);
localPaint.setStrokeWidth(3.0F * this.getDisplayScale);
localPaint.setAlpha(75);
for (int k = 0; ; k++) {
if (k > 4) {
localPaint.setAlpha(100);
localPaint.setStyle(Paint.Style.FILL);
localPaint.setShader(new SweepGradient(i, i, 0, -16711936));
if (paramBoolean.booleanValue()) {
RectF localRectF = new RectF();
localRectF.set(i - j, i - j, i + j, i + j);
localCanvas.drawArc(localRectF, 0.0F, 360.0F, true, localPaint);
}
localPaint.setShader(null);
localPaint.setAlpha(255);
localPaint.setColor(Color.parseColor("#810003"));
localPaint.setStyle(Paint.Style.FILL);
localPaint.setStrokeWidth(0.0F);
localCanvas.drawCircle(i, i, 10.0F * this.getDisplayScale, localPaint);
return localBitmap;
}
localCanvas.drawCircle(i, i, j - k * 40 * this.getDisplayScale, localPaint);
}
}
public Bitmap drawRadarGhosts(Boolean paramBoolean) {
Bitmap localBitmap = Bitmap
.createBitmap(-50 + this.getDisplayWidth, -50 + this.getDisplayWidth,
Bitmap.Config.ARGB_8888);
Canvas localCanvas = new Canvas(localBitmap);
Paint localPaint = new Paint();
if (paramBoolean.booleanValue()) {
int i = (int) ((localBitmap.getWidth() - 10.0F * this.getDisplayScale) / 2.0F
+ 5.0F * this.getDisplayScale);
int j = (int) (i - 5.0F * this.getDisplayScale);
localPaint.setAntiAlias(true);
localPaint.setAlpha(255);
Random localRandom = new Random();
localPaint.setAlpha(150);
int k = localRandom.nextInt(180);
int m = localRandom.nextInt(j);
int n = i + (int) (Math.cos(3.141592653589793D * k / 180.0D) * m);
int i1 = i + (int) (Math.sin(3.141592653589793D * k / 180.0D) * m);
localPaint.setColor(-16711936);
localPaint.setShader(
new RadialGradient(n, i1, 22.0F * this.getDisplayScale, -16711936, 0,
TileMode.CLAMP));
localCanvas.drawCircle(n, i1, 15.0F * this.getDisplayScale, localPaint);
if (localRandom.nextInt(50) < 5) {
int i6 = localRandom.nextInt(180);
int i7 = localRandom.nextInt(j);
int i8 = i + (int) (Math.cos(3.141592653589793D * i6 / 180.0D) * i7);
int i9 = i + (int) (Math.sin(3.141592653589793D * i6 / 180.0D) * i7);
localPaint.setShader(
new RadialGradient(i8, i9, 22.0F * this.getDisplayScale, -16711936, 0,
TileMode.CLAMP));
localCanvas.drawCircle(i8, i9, 15.0F * this.getDisplayScale, localPaint);
}
if (localRandom.nextInt(75) < 5) {
int i2 = localRandom.nextInt(180);
int i3 = localRandom.nextInt(j);
int i4 = i + (int) (Math.cos(3.141592653589793D * i2 / 180.0D) * i3);
int i5 = i + (int) (Math.sin(3.141592653589793D * i2 / 180.0D) * i3);
localPaint.setShader(
new RadialGradient(i4, i5, 22.0F * this.getDisplayScale, -16711936, 0,
TileMode.CLAMP));
localCanvas.drawCircle(i4, i5, 15.0F * this.getDisplayScale, localPaint);
}
}
return localBitmap;
}
public void onCreate(Bundle paramBundle) {
Log.i("com.example.ghostsam", "onStart RadarScreen");
requestWindowFeature(1);
getWindow().setFlags(1024, 1024);
super.onCreate(paramBundle);
setContentView(R.layout.radarscreen);
SharedPreferences localSharedPreferences = getSharedPreferences("app_prefs", 0);
int i = localSharedPreferences.getInt("appStartCounter", 0);
int j = localSharedPreferences.getInt("appStartFirst", 0);
int k = i + 1;
SharedPreferences.Editor localEditor = localSharedPreferences.edit();
localEditor.putInt("appStartCounter", k);
if (j <= 0) {
localEditor.putInt("appStartFirst", (int) (System.currentTimeMillis() / 1000L));
}
localEditor.commit();
if ((k == 5) || (k == 10) || (k == 25)) {
AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
localBuilder.setIcon(17301543);
Resources localResources1 = getResources();
Object[] arrayOfObject1 = new Object[1];
arrayOfObject1[0] = "name";
localBuilder.setTitle(localResources1.getString(R.string.app_name, arrayOfObject1));
Resources localResources2 = getResources();
Object[] arrayOfObject2 = new Object[1];
arrayOfObject2[0] = "name";
localBuilder.setMessage(localResources2
.getString(R.string.dialog_ratemarket_question, arrayOfObject2));
Resources localResources3 = getResources();
Object[] arrayOfObject3 = new Object[1];
arrayOfObject3[0] = "name";
localBuilder.setPositiveButton(
localResources3.getString(R.string.dialog_button_yes, arrayOfObject3),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface paramDialogInterface,
int paramInt) {
Resources localResources = RadarScreen.this.getResources();
Object[] arrayOfObject = new Object[1];
arrayOfObject[0] = "name";
Intent localIntent = new Intent("android.intent.action.VIEW",
Uri.parse(localResources.getString(R.string.app_marketlink,
arrayOfObject)));
RadarScreen.this.startActivity(localIntent);
paramDialogInterface.dismiss();
}
});
Resources localResources4 = getResources();
Object[] arrayOfObject4 = new Object[1];
arrayOfObject4[0] = "name";
localBuilder.setNegativeButton(
localResources4.getString(R.string.dialog_button_no, arrayOfObject4),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface paramDialogInterface,
int paramInt) {
paramDialogInterface.dismiss();
}
});
localBuilder.create().show();
}
}
public boolean onCreateOptionsMenu(Menu paramMenu) {
getMenuInflater().inflate(R.menu.radarscreen, paramMenu);
return true;
}
public void onError(Exception paramException) {
}
public void onIllegalHttpStatusCode(int paramInt, String paramString) {
}
public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {
if (paramInt == 4) {
quitApp();
}
for (int i = 1; ; i = 0) {
return true;
}
}
@SuppressLint("NewApi")
public boolean onOptionsItemSelected(MenuItem paramMenuItem) {
switch (paramMenuItem.getItemId()) {
default:
break;
case R.id.radarscreen_menu_moreapps:
Resources localResources2 = getResources();
Object[] arrayOfObject2 = new Object[1];
arrayOfObject2[0] = "name";
startActivity(new Intent("android.intent.action.VIEW", Uri.parse(localResources2
.getString(R.string.app_marketdeveloperlink, arrayOfObject2))));
break;
case R.id.radarscreen_menu_rateapp:
Resources localResources1 = getResources();
Object[] arrayOfObject1 = new Object[1];
arrayOfObject1[0] = "name";
startActivity(new Intent("android.intent.action.VIEW", Uri.parse(
localResources1.getString(R.string.app_marketlink, arrayOfObject1))));
break;
case R.id.radarscreen_menu_about:
startActivity(new Intent(this, About.class));
break;
case R.id.radarscreen_menu_settings:
startActivity(new Intent(this, Settings.class));
break;
case R.id.radarscreen_menu_quit:
quitApp();
}
return true;
}
public void onResume() {
super.onResume();
Log.i("com.example.ghostsam", "onResume RadarScreen");
getWindowManager().getDefaultDisplay().getMetrics(this.getDisplay);
this.getDisplayWidth = this.getDisplay.widthPixels;
this.getDisplayHeight = this.getDisplay.heightPixels;
this.getDisplayScale = (this.getDisplayWidth / 480.0F);
this.layoutFontFace = Typeface.createFromAsset(getAssets(), "Roboto-Regular.ttf");
this.settingsGeneralVibrate = PreferenceManager
.getDefaultSharedPreferences(getBaseContext())
.getBoolean("settings_general_vibrate", true);
this.vib = ((Vibrator) getSystemService("vibrator"));
this.ivLogo = ((ImageView) findViewById(R.id.ivLogo));
this.ivLogo.setImageBitmap(Bitmap.createScaledBitmap(
BitmapFactory.decodeResource(getResources(), R.drawable.logo),
(int) (460.0F * this.getDisplayScale), (int) (68.0F * this.getDisplayScale),
true));
this.ivSignalButton = ((ImageView) findViewById(R.id.ivSignalButton));
this.ivSignalButton.setImageBitmap(drawButton("start radar", "#005F21"));
this.ivSignalButton.setOnTouchListener(this);
this.ivRadar = ((ImageView) findViewById(R.id.ivRadar));
this.ivRadar.setImageBitmap(drawRadar(Boolean.valueOf(false)));
this.ivRadarGhosts = ((ImageView) findViewById(R.id.ivRadarGhosts));
if (this.ivRadarGhosts != null) {
this.ivRadarGhosts.setImageBitmap(drawRadarGhosts(Boolean.valueOf(false)));
}
this.countdownShowGhost = new CountDownTimer(15000L, 1000L) {
public void onFinish() {
RadarScreen.this.showGhosts = Boolean.valueOf(false);
RadarScreen.this.hideGhosts = Boolean.valueOf(false);
if (RadarScreen.this.countdownHideGhost != null) {
RadarScreen.this.countdownHideGhost.start();
}
}
public void onTick(long paramLong) {
Random localRandom = new Random();
if (!RadarScreen.this.showGhosts.booleanValue()) {
RadarScreen.this.showGhosts = Boolean.valueOf(true);
RadarScreen.this.showGhostsZufallszahl = (1000 + localRandom
.nextInt(10000));
if (localRandom.nextInt(50) >= 10) {
AlphaAnimation localAlphaAnimation2 = new AlphaAnimation(0.0F, 0.975F);
localAlphaAnimation2.setDuration(1000L);
localAlphaAnimation2.setFillAfter(true);
if (RadarScreen.this.ivRadarGhosts != null) {
RadarScreen.this.ivRadarGhosts.startAnimation(localAlphaAnimation2);
RadarScreen.this.ivRadarGhosts.setImageBitmap(
RadarScreen.this.drawRadarGhosts(Boolean.valueOf(true)));
if (RadarScreen.this.settingsGeneralVibrate) {
RadarScreen.this.vib.vibrate(20L);
}
}
}
}
if ((RadarScreen.this.showGhostsZufallszahl > paramLong) && (!RadarScreen.this
.hideGhosts.booleanValue())) {
RadarScreen.this.hideGhosts = Boolean.valueOf(true);
AlphaAnimation localAlphaAnimation1 = new AlphaAnimation(0.975F, 0.0F);
localAlphaAnimation1.setDuration(1000L);
localAlphaAnimation1.setFillAfter(true);
if (RadarScreen.this.ivRadarGhosts == null) {
return;
}
RadarScreen.this.ivRadarGhosts.startAnimation(localAlphaAnimation1);
}
}
};
this.countdownHideGhost = new CountDownTimer(12500L, 2250L) {
public void onFinish() {
RadarScreen.this.showGhosts = Boolean.valueOf(false);
RadarScreen.this.hideGhosts = Boolean.valueOf(false);
if (RadarScreen.this.countdownShowGhost != null) {
RadarScreen.this.countdownShowGhost.start();
}
}
public void onTick(long paramLong) {
}
};
}
public void onStop() {
super.onStop();
Log.i("com.example.ghostsam", "onStop RadarScreen");
BitmapDrawable localBitmapDrawable1 = (BitmapDrawable) this.ivLogo.getDrawable();
this.ivLogo.setImageBitmap(null);
this.ivLogo.setImageDrawable(null);
this.ivLogo = null;
Bitmap localBitmap1 = localBitmapDrawable1.getBitmap();
if ((localBitmap1 != null) && (!localBitmap1.isRecycled()))
{
localBitmap1.recycle();
}
BitmapDrawable localBitmapDrawable2 = (BitmapDrawable) this.ivRadar.getDrawable();
this.ivRadar.setImageBitmap(null);
this.ivRadar.setImageDrawable(null);
this.ivRadar = null;
Bitmap localBitmap2 = localBitmapDrawable2.getBitmap();
if ((localBitmap2 != null) && (!localBitmap2.isRecycled()))
{
localBitmap2.recycle();
}
BitmapDrawable localBitmapDrawable3 = (BitmapDrawable) this.ivRadarGhosts.getDrawable();
this.ivRadarGhosts.setImageBitmap(null);
this.ivRadarGhosts.setImageDrawable(null);
this.ivRadarGhosts = null;
Bitmap localBitmap3 = localBitmapDrawable3.getBitmap();
if ((localBitmap3 != null) && (!localBitmap3.isRecycled()))
{
localBitmap3.recycle();
}
BitmapDrawable localBitmapDrawable4 = (BitmapDrawable) this.ivSignalButton
.getDrawable();
this.ivSignalButton.setImageBitmap(null);
this.ivSignalButton.setImageDrawable(null);
this.ivSignalButton = null;
Bitmap localBitmap4 = localBitmapDrawable4.getBitmap();
if ((localBitmap4 != null) && (!localBitmap4.isRecycled()))
{
localBitmap4.recycle();
}
this.countdownHideGhost.cancel();
this.countdownHideGhost = null;
this.countdownShowGhost.cancel();
this.countdownShowGhost = null;
this.radarRun = Boolean.valueOf(false);
this.showGhosts = Boolean.valueOf(false);
this.hideGhosts = Boolean.valueOf(false);
}
public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
switch (paramMotionEvent.getAction()) {
default:
if (paramView != this.ivSignalButton) {
break;
}
case 0:
if (this.radarRun.booleanValue()) {
if (this.radarRun.booleanValue()) {
if (this.ivSignalButton == null) {
break;
}
this.ivSignalButton.setImageBitmap(drawButton("stop radar", "#1BA449"));
}
}
case 1:
if (this.ivSignalButton == null) {
break;
}
this.ivSignalButton.setImageBitmap(drawButton("start radar", "#1BA449"));
}
// while (paramView != this.ivSignalButton);
if (this.radarRun.booleanValue()) {
if (this.ivSignalButton != null) {
this.ivSignalButton.setImageBitmap(drawButton("stop radar", "#005F21"));
}
if ((paramMotionEvent.getX() <= 0.0F) || (paramMotionEvent.getX() >= paramView
.getWidth()) ||
(paramMotionEvent.getY() <= 0.0F) || (paramMotionEvent.getY() >= paramView
.getHeight())) {
this.ivSignalButton.setImageBitmap(drawButton("stop radar", "#005F21"));
}
if (this.ivSignalButton != null) {
this.ivSignalButton.setImageBitmap(drawButton("start radar", "#005F21"));
}
RotateAnimation localRotateAnimation = new RotateAnimation(0.0F, 360.0F, 1, 0.5F, 1,
0.5F);
localRotateAnimation.setInterpolator(new LinearInterpolator());
localRotateAnimation.setFillAfter(true);
localRotateAnimation.setRepeatMode(1);
if (!this.radarRun.booleanValue()) {
if (this.ivSignalButton != null) {
this.ivSignalButton.setImageBitmap(drawButton("stop radar", "#005F21"));
}
}
this.radarRun = Boolean.valueOf(true);
this.radarRun = Boolean.valueOf(false);
if (this.ivRadar != null) {
this.ivRadar.setImageBitmap(drawRadar(Boolean.valueOf(false)));
}
localRotateAnimation.setDuration(10L);
localRotateAnimation.setRepeatCount(0);
if (this.ivRadarGhosts != null) {
this.ivRadarGhosts.setImageBitmap(drawRadarGhosts(Boolean.valueOf(false)));
}
if (this.countdownHideGhost != null) {
this.countdownHideGhost.cancel();
}
if (this.countdownHideGhost != null) {
this.countdownShowGhost.cancel();
}
}
if (this.ivSignalButton == null) {
this.ivSignalButton.setImageBitmap(drawButton("start radar", "#005F21"));
}
if (this.ivRadar != null) {
this.ivRadar.setImageBitmap(drawRadar(Boolean.valueOf(true)));
}
localRotateAnimation.setDuration(3000L);
localRotateAnimation.setRepeatCount(-1);
if (this.countdownHideGhost == null) {
this.countdownHideGhost.start();
}
this.ivRadar.startAnimation(localRotateAnimation);
return true;
}
}
Upvotes: 0
Views: 237
Reputation: 14226
You have to problems here:
RotateAnimation localRotateAnimation
but never assigned a value to it. That's why you get a NullPointerException.RotateAnimation localRotateAnimation = new RotateAnimation(0.0F, 360.0F, 1, 0.5F, 1, 0.5F);
. Most likly, you wanted to use the filed. So change that to just localRotateAnimation = new RotateAnimation(/*params*/);
I'm not sure if fixing 2. fixes 1. because I did not understand your logic. Maybe 2. gets called every time before you reach the code which throws the NPE now.
Maybe you need to assign a value somewhere else to.
Maybe this code block is what you want:
// moved up to run it even if condition is false
// and use field
localRotateAnimation = new RotateAnimation(0.0F, 360.0F, 1, 0.5F, 1, 0.5F);
if (this.radarRun.booleanValue()) {
if (this.ivSignalButton != null) {
this.ivSignalButton.setImageBitmap(drawButton("stop radar", "#005F21"));
}
if ((paramMotionEvent.getX() <= 0.0F) || (paramMotionEvent.getX() >= paramView
.getWidth()) ||
(paramMotionEvent.getY() <= 0.0F) || (paramMotionEvent.getY() >= paramView
.getHeight())) {
this.ivSignalButton.setImageBitmap(drawButton("stop radar", "#005F21"));
}
if (this.ivSignalButton != null) {
this.ivSignalButton.setImageBitmap(drawButton("start radar", "#005F21"));
}
localRotateAnimation.setInterpolator(new LinearInterpolator());
localRotateAnimation.setFillAfter(true);
localRotateAnimation.setRepeatMode(1);
if (!this.radarRun.booleanValue()) {
if (this.ivSignalButton != null) {
this.ivSignalButton.setImageBitmap(drawButton("stop radar", "#005F21"));
}
}
this.radarRun = Boolean.valueOf(true);
this.radarRun = Boolean.valueOf(false);
if (this.ivRadar != null) {
this.ivRadar.setImageBitmap(drawRadar(Boolean.valueOf(false)));
}
localRotateAnimation.setDuration(10L);
localRotateAnimation.setRepeatCount(0);
if (this.ivRadarGhosts != null) {
this.ivRadarGhosts.setImageBitmap(drawRadarGhosts(Boolean.valueOf(false)));
}
if (this.countdownHideGhost != null) {
this.countdownHideGhost.cancel();
}
if (this.countdownHideGhost != null) {
this.countdownShowGhost.cancel();
}
}
if (this.ivSignalButton == null) {
this.ivSignalButton.setImageBitmap(drawButton("start radar", "#005F21"));
}
if (this.ivRadar != null) {
this.ivRadar.setImageBitmap(drawRadar(Boolean.valueOf(true)));
}
localRotateAnimation.setDuration(3000L);
localRotateAnimation.setRepeatCount(-1);
if (this.countdownHideGhost == null) {
this.countdownHideGhost.start();
}
this.ivRadar.startAnimation(localRotateAnimation);
Upvotes: 1