Bitmap을 ImageView에 연결할 때 문제가 있습니다. 이것은 내가 오류 얻을 수있다 :Android Studio : Bitmap to ImageView 오류
public SimulationView(Context context) {
super(context);
mXOrigin = 50;
mYOrigin = 50;
mHorizontalBound = 100;
mVerticalBound = 100;
//Sensor Manager
sensorManager = (SensorManager)context.getSystemService(SENSOR_SERVICE);
Bitmap ball = BitmapFactory.decodeResource(getResources(), R.drawable.ball);
iBall.setImageBitmap(ball);
mBitmap = Bitmap.createScaledBitmap(ball, BALL_SIZE, BALL_SIZE, true);
Bitmap basket = BitmapFactory.decodeResource(getResources(), R.drawable.basket);
mBasket = Bitmap.createScaledBitmap(basket, BASKET_SIZE, BASKET_SIZE, true);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inDither = true;
opts.inPreferredConfig = Bitmap.Config.RGB_565;
mField = BitmapFactory.decodeResource(getResources(), R.drawable.field, opts);
WindowManager mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay();
}
:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: accelerometer.example.com.accgame, PID: 25897
...
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
내가이 널 포인터 예외는 알고 있지만의 GetResources()가 null를 돌려 내가 왜 아무 생각이 ... 여기 내 생성자 클래스 기본적으로이 오류는 줄을 강조 표시합니다. iBall.setImageBitmap(ball);
이미지 자체에 관해서는 드로어 블 폴더에 배치해야합니다. 그것은 .jpg 파일이고 나는 그것을 많이 축소했습니다.
한 OnCreate에서
대신의 GetResources()의() context.getResources를 사용하여 보시기 바랍니다 .. –
안녕하세요, 그 작동하지 않았다 ... 내 주요 활동에서 (이 그냥 AppCompatActivity 확장) 다음 코드에 의해 내 SimulationView 호출 오전 : SimulationView 뷰 =보기 = 새로운 SimulationView (...) 내가 통과 해야하는 무엇입니까? – futureLookingGrimm
오류 메시지와 관련하여'iBall'이 null입니다. 찾으십시오, 왜, 그 대답이 될 것입니다. –