Skip to main content

Posts

Showing posts with the label Java

Spring Boot 3 Migration: Resolving javax to jakarta ClassNotFoundExceptions

The Crash You have just bumped your version numbers in  pom.xml  or  build.gradle  to upgrade from Spring Boot 2.7 to Spring Boot 3.0+. You compile successfully, but upon runtime startup or the first HTTP request, the application crashes with a stack trace resembling this: java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest at com.example.config.SecurityConfig.configure(SecurityConfig.java:24) at ... Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ... Or perhaps an error related to JPA: java.lang.NoClassDefFoundError: javax/persistence/Entity This is the single most common blocking issue in Spring Boot 3 migrations. It is not a bug in your code logic; it is a binary incompatibility caused by a massive ecosystem sh...

android - Get current activity root view

MainActivity.java package com.cfsuman.androidtutorials; import android.graphics.Color; import android.os.Bundle; import android.app.Activity; import android.view.ViewGroup; import android.widget.Button; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the widgets reference from XML layout Button button = findViewById(R.id.button); // Set a click listener for Button widget button.setOnClickListener(view -> { // Get the view which you added by // activity setContentView() method. ViewGroup viewGroup = (ViewGroup) ((ViewGroup) (findViewById(android.R.id.content))) .getChildAt(0); viewGroup.setBackgroundColor( Color.parseColor("#676767") ); }); } } acti...

android - Request multiple permissions example

activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/root_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" android:orientation="vertical" android:background="#e5ead3" > <Button android:id="@+id/btn_do_task" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Check Permissions" /> </LinearLayout> MainActivity.java package com.cfsuman.me.androidcodesnippets; import android.Manifest; import android.app.Activity; import android.app.AlertDialog; import android...