###発生している問題・エラーメッセージ
該当の箇所およびそれに関わるところはいじってないはずなのですが、そこでNullPointerExceptionが発生しました。
Process: jpdb.shoichi_vono_kono.airchainsaw, PID: 14213 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
エラーメッセージにはBitmapのgetWidth()によるとありますが、該当のコードはcreateScaledBitmapで、getWidth()は使ってないのでなぜそうなるのか全く分かりません。
###該当のソースコード(追記)
xml
1<?xml version="1.0" encoding="utf-8"?> 2<FrameLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 android:layout_height="match_parent" 5 android:layout_width="match_parent"> 6<jpdb.shoichi_vono_kono.airchainsaw.C 7 android:id="@+id/display" 8 android:layout_width="match_parent" 9 android:layout_height="match_parent" /> 10</FrameLayout>
上はsurfaceViewを扱っているファイルを含むxmlファイルです。
Cがファイル名です。
java
1protected void onCreate(Bundle savedInstanceState) { 2 super.onCreate(savedInstanceState); 3 Intent ii = getIntent(); 4 BIngo = ii.getBooleanExtra("BINGOOO", false); 5 requestWindowFeature(Window.FEATURE_NO_TITLE); 6 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 7 setNavigationbarHide(this, true); 8 mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); 9 mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); 10 mAccele = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); 11 LayoutInflater factory = LayoutInflater.from(this); 12 FrameLayout root = new FrameLayout(this); 13 View view = factory.inflate(R.layout.mix, root); 14 setContentView(view); 15 cccc = (C) findViewById(R.id.display); 16 String h1 = (String) getText(R.string.radar); 17 cccc.setUr(h1); 18 cccc.setBINGo(BIngo); 19 }
使用元のonCreateの部分です
###試したこと
引数を変数から数字に変えたりしてみました。
###追記(関連するメソッドについて)
まず、関連するメソッドはmakeBitmap()とBitmap.createScaledBitmap()です。
java
1DisplayMetrics metrics = new DisplayMetrics(); 2 windowManager.getDefaultDisplay().getMetrics(metrics); 3 int _wDpi = (int)metrics.densityDpi; 4 res = this.getContext().getResources(); 5 6 try { 7 ufo = makeBitmap(_wDpi, res, R.drawable.ufocomp, getWidth(), getHeight()); 8 starmaemae = makeBitmap(_wDpi, res, R.drawable.starskymaemae, getWidth(), getHeight()); 9 starmae = makeBitmap(_wDpi, res, R.drawable.starskymae, getWidth(), getHeight()); 10 starushiro = makeBitmap(_wDpi, res, R.drawable.starskyushiro, getWidth(), getHeight()); 11 starushiroushiro = makeBitmap(_wDpi, res, R.drawable.starskyushiroushiro, getWidth(), getHeight()); 12 ya = makeBitmap(_wDpi, res, R.drawable.yajirushi, getWidth(), getHeight()); 13 }catch (OutOfMemoryError e) { 14 Log.d("OutOfMemory", "happen"); 15 } 16 17 try { 18 ufo = Bitmap.createScaledBitmap(ufo, 150, 150, false); 19 starmaemae = Bitmap.createScaledBitmap(starmaemae, (int) (starmaemaeoutw * 2.5f), (int) (starmaemaeouth * 2.5f), false); 20 starmae = Bitmap.createScaledBitmap(starmae, (int) (starmaeoutw * 2.5f), (int) (starmaeouth * 2.5f), false); 21 starushiro = Bitmap.createScaledBitmap(starushiro, (int) (starushioutw * 2.5f), (int) (starushiouth * 2.5f), false); 22 starushiroushiro = Bitmap.createScaledBitmap(starushiroushiro, (int) (starushiushioutw * 2.5f), (int) (starushiushiouth * 2.5f), false); 23 ya = Bitmap.createScaledBitmap(ya, 175, 175, false); 24 }catch (OutOfMemoryError e) { 25 Log.d("OutOfMemory", "happen"); 26 }
呼び出し順は上の通り、makeBitmap()群が最初で次にBitmap.createScaledBitmap()群が呼ばれるようになっています。
###追記(各値)
wDpi=480, MaxWidth=1080, MaxHeight=1920, scale=0.33333334, max=0.0
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。