Reputation: 5634
I want to initialize and display a four by four grid of circles. I'm recieving two errors:
1 is actually a warning: The static method createBitmap from type bitmap should be accessed in a static way.
1 error: The constructor Bitmap() is not visible.
Below is my code.
package com.example.dcubebluetooth;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
public class LEDView extends View{
Paint background = new Paint();
Paint black = new Paint();
Paint red = new Paint();
int numRows = 4;
int numCols = 4;
Bitmap[][] leds = new Bitmap[numRows][numCols];
Canvas ledDrawer = new Canvas();
public LEDView(Context context) {
super(context);
background.setARGB(255, 255, 255, 255);
black.setARGB(255, 0, 0, 0);
red.setARGB(255, 255, 0, 0);
for(int y=0; y<numCols; y++){
for(int x=0; x<numRows; x++){
Bitmap map = Bitmap.createBitmap(100, 100, Config.RGB_565); //Error here
leds[x][y] = map;
ledDrawer.setBitmap(leds[x][y]);
ledDrawer.drawCircle(50, 50, 50, black);
}
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawPaint(background);
for(int y=0; y<numCols; y++){
for(int x=0; x<numRows; x++){
canvas.drawBitmap(leds[x][y], x*100, y*100, null);
}
}
}
}
I did a previous project in which I did this and it gave me no errors or warnings:
//Instance variable
Bitmap touchPad;
//In constructor
touchPad = Bitmap.createBitmap(screenWidth, (int) (screenHeight*0.75), Config.RGB_565);
What is the difference between the two?
Extra information: The four by four grid will represent a layer of LEDs connected to my microcontroller. I'm gonna have four other buttons to the side to change between layers and some more arrays to store current state.
Upvotes: 0
Views: 722
Reputation: 7027
There isn't any error or warning on this code! (i tested here)
You are probably seeing old warnings/errors from lint, try to clean them: Right click on the project > Android Tools > Clear Lint Markers
This warning/error happens when you are calling createBitmap from a Bitmap instance, example:
Bitmap bmp = new Bitmap();
bmp.createBitmap(100, 100, Config.RGB_565);
Upvotes: 1