I don't understand why this error is popping up as I've debugged and gone through my source code multiple times now. Any help would be really appreciated!
<?xml version="1.0"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="350dp"
android:layout_height="350dp"
android:src="@drawable/color"
android:contentDescription="@string/todo" />
<View
android:id="@+id/colorView"
android:layout_width="match_parent"
android:layout_height="100dp"/>
<TextView
android:id="@+id/resultTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HEX: \nRGB"
android:textSize="25sp"
android:textColor="#000"/>
</LinearLayout>
Thats the .XML file
package com.example.myapplication;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
ImageView mImageView;
TextView mResultTv;
View mColorView;
Bitmap bitmap;
@SuppressLint({"ClickableViewAccessibility", "SetTextI18n"})
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageView = findViewById(R.id.imageView);
mResultTv = findViewById(R.id.resultTv);
mColorView = findViewById(R.id.colorView);
mImageView.setDrawingCacheEnabled(true);
mImageView.buildDrawingCache(true);
mImageView.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
bitmap = mImageView.getDrawingCache();
int pixel = bitmap.getPixel((int) event.getX(), (int) event.getY());
int r = Color.red(pixel);
int g = Color.green(pixel);
int b = Color.blue(pixel);
String hex = "#" + Integer.toHexString(pixel);
mColorView.setBackgroundColor(Color.rgb(r, g, b));
mResultTv.setText("RGB: " + r + ", " + g + ", " + b + "\nHEX: " + hex);
Log.d("SOMIL KEY", String.valueOf(r));
}
return true;
});
}
}
This is the .java file
The error I'm facing: Message: An invalid XML character (Unicode: 0x0) was found in the element content of the document.
I've combed through stack exchange as well as a lot of other forums and can't find a good answer.