SQLite Database Android .......... just basic thing < Dont know y dosent work :/ > - sql

I was just learning about sqlite databases and tried a small application to just add entries into a sqlite data base ....... don't know why it doesn't work ..... I'm really frustrated and almost to lose my interest on this android stuff ....... any help is appreciated ...... Thank you in advance ..........
this is the code :
opener class
package com.example.sqlite;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class opener {
Context cc;
SQLiteDatabase db;
public opener(Context c)
{
cc=c;
}
class SQLHelper extends SQLiteOpenHelper{
public SQLHelper(Context context) {
super(context, "app" , null, 1);
// TODO Auto-generated constructor stub
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE default(name TEXT, abc TEXT, ac TEXT)");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS default");
onCreate(db);
}
}
public void open()
{
SQLHelper sq= new SQLHelper(cc);
db=sq.getWritableDatabase();
}
public void close()
{
db.close();
}
public long insert(String a,String b,String c)
{
ContentValues cv = new ContentValues();
cv.put("name", a);
cv.put("abc", b);
cv.put("ac", c);
return db.insert("default", null,cv);
}
}
This is the main class :
MainActivity.java
package com.example.sqlite;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText ed1;
EditText ed2;
EditText ed3;
EditText ed4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = (EditText) findViewById(R.id.editText1);
ed2 = (EditText) findViewById(R.id.editText2);
ed3 = (EditText) findViewById(R.id.editText3);
ed4 = (EditText) findViewById(R.id.editText4);
}
public void add(View v) {
String ac = ed1.getText().toString();
String b = ed2.getText().toString();
String c = ed3.getText().toString();
opener a = new opener(this);
a.open();
long d = a.insert(ac, b, c);
a.close();
if (d != -1) {
Dialog dia = new Dialog(this);
dia.setTitle("SUCCESS");
dia.setCanceledOnTouchOutside(true);
dia.show();
}
else {
Dialog dia = new Dialog(this);
dia.setTitle("NoSuccess");
dia.setCanceledOnTouchOutside(true);
dia.show();
}
}}
And by the way sorry if it looks messy .....
The console says something like this whenever i try to insert something
07-04 12:45:57.951: I/Database(277): sqlite returned: error code = 1, msg = near "default": syntax error
07-04 12:45:57.951: E/Database(277): Failure 1 (near "default": syntax error) on 0x32a270 when preparing 'CREATE TABLE default(name TEXT, abc TEXT, ac TEXT)'.
07-04 12:45:57.961: D/AndroidRuntime(277): Shutting down VM
07-04 12:45:57.961: W/dalvikvm(277): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-04 12:45:58.011: E/AndroidRuntime(277): FATAL EXCEPTION: main
07-04 12:45:58.011: E/AndroidRuntime(277): java.lang.IllegalStateException: Could not execute method of the activity
07-04 12:45:58.011: E/AndroidRuntime(277): at android.view.View$1.onClick(View.java:2072)
07-04 12:45:58.011: E/AndroidRuntime(277): at android.view.View.performClick(View.java:2408)
07-04 12:45:58.011: E/AndroidRuntime(277): at android.view.View$PerformClick.run(View.java:8816)
07-04 12:45:58.011: E/AndroidRuntime(277): at android.os.Handler.handleCallback(Handler.java:587)
07-04 12:45:58.011: E/AndroidRuntime(277): at android.os.Handler.dispatchMessage(Handler.java:92)
07-04 12:45:58.011: E/AndroidRuntime(277): at android.os.Looper.loop(Looper.java:123)
07-04 12:45:58.011: E/AndroidRuntime(277): at a
android.app.ActivityThread.main(ActivityThread.java:4627)
07-04 12:45:58.011: E/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 12:45:58.011: E/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
07-04 12:45:58.011: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-04 12:45:58.011: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-04 12:45:58.011: E/AndroidRuntime(277): at dalvik.system.NativeStart.main(Native Method)
07-04 12:45:58.011: E/AndroidRuntime(277): Caused by: java.lang.reflect.InvocationTargetException
07-04 12:45:58.011: E/AndroidRuntime(277): at com.example.sqlite.MainActivity.add(MainActivity.java:31)
07-04 12:45:58.011: E/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 12:45:58.011: E/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
07-04 12:45:58.011: E/AndroidRuntime(277): at android.view.View$1.onClick(View.java:2067)
07-04 12:45:58.011: E/AndroidRuntime(277): ... 11 more
07-04 12:45:58.011: E/AndroidRuntime(277): Caused by: android.database.sqlite.SQLiteException: near "default": syntax error: CREATE TABLE
default(name TEXT, abc TEXT, ac TEXT)
07-04 12:45:58.011: E/AndroidRuntime(277): at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
07-04 12:45:58.011: E/AndroidRuntime(277): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1727)
07-04 12:45:58.011: E/AndroidRuntime(277): at com.example.sqlite.opener$SQLHelper.onCreate(opener.java:29)
07-04 12:45:58.011: E/AndroidRuntime(277): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
07-04 12:45:58.011: E/AndroidRuntime(277): at com.example.sqlite.opener.open(opener.java:45)
Thanks in advance

DEFAULT is an SQL keyword that must be quoted every time it is used in SQL statements:
db.execSQL("CREATE TABLE \"default\"(name TEXT, abc TEXT, ac TEXT)");
...
db.execSQL("DROP TABLE IF EXISTS \"default\"");
...
db.insert("\"default\"", null, cv);
You might be better of using another name.

Related

java.lang.IllegalStateException: UT010057: multipart config was not present on Servlet

I annotated both the resource class and the class that extends Application with #MultipartConfig, but I'm still getting the error: "org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalStateException: UT010057: multipart config was not present on Servlet". The application server I'm using is WildFly 25.
Resource class:
import javax.servlet.ServletException;
import java.io.IOException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
#MultipartConfig
#Path("/")
public class File {
#Path("/upload")
#POST
public Response upload(#Context HttpServletRequest request) throws ServletException, IOException {
request.getParts();
return null;
}
}
JaxRsActivator class:
import javax.servlet.annotation.MultipartConfig;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/api")
#MultipartConfig
public class JaxRsActivator extends Application {
}
Error message with stack trace:
ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /test/api/upload: org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalStateException: UT010057: multipart config was not present on Servlet
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:106)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:372)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:218)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:519)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:249)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:60)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
at javax.servlet.api#2.0.0.Final//javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.security.elytron-web.undertow-server#1.9.1.Final//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.lambda$handleRequest$1(ElytronRunAsHandler.java:68)
at org.wildfly.security.elytron-base#1.17.1.Final//org.wildfly.security.auth.server.FlexibleIdentityAssociation.runAsFunctionEx(FlexibleIdentityAssociation.java:103)
at org.wildfly.security.elytron-base#1.17.1.Final//org.wildfly.security.auth.server.Scoped.runAsFunctionEx(Scoped.java:161)
at org.wildfly.security.elytron-base#1.17.1.Final//org.wildfly.security.auth.server.Scoped.runAs(Scoped.java:73)
at org.wildfly.security.elytron-web.undertow-server#1.9.1.Final//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.handleRequest(ElytronRunAsHandler.java:67)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.core#2.2.12.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.core#2.2.12.Final//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.core#2.2.12.Final//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at org.wildfly.security.elytron-web.undertow-server-servlet#1.9.1.Final//org.wildfly.elytron.web.undertow.server.servlet.CleanUpHandler.handleRequest(CleanUpHandler.java:38)
at io.undertow.core#2.2.12.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow#25.0.0.Final//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.core#2.2.12.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow#25.0.0.Final//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
at io.undertow.core#2.2.12.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:280)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:79)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:134)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:131)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow#25.0.0.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at org.wildfly.extension.undertow#25.0.0.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at org.wildfly.extension.undertow#25.0.0.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at org.wildfly.extension.undertow#25.0.0.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:260)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:79)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:100)
at io.undertow.core#2.2.12.Final//io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
at io.undertow.core#2.2.12.Final//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:852)
at org.jboss.threads#2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads#2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at org.jboss.xnio#3.8.4.Final//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalStateException: UT010057: multipart config was not present on Servlet
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.spec.HttpServletRequestImpl.verifyMultipartServlet(HttpServletRequestImpl.java:543)
at io.undertow.servlet#2.2.12.Final//io.undertow.servlet.spec.HttpServletRequestImpl.getParts(HttpServletRequestImpl.java:532)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.ContextParameterInjector$GenericDelegatingProxy.invoke(ContextParameterInjector.java:166)
at io.undertow.servlet#2.2.12.Final/jdk.proxy13/jdk.proxy13.$Proxy47.getParts(Unknown Source)
at deployment.test-upload-1.0.war//test.File.upload(File.java:19)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:170)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:660)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:524)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:474)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:476)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:434)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:408)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:69)
at org.jboss.resteasy.resteasy-core#4.7.2.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:492)
... 53 more

Caused by: com.google.firebase.database.DatabaseException:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.poster, PID: 23677
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.poster/com.example.poster.MainActivity}: com.google.firebase.database.DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your getInstance() call.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: com.google.firebase.database.DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your getInstance() call.
at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database##16.0.4:114)
at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database##16.0.4:71)
at com.example.poster.MainActivity.onCreate(MainActivity.java:48)
at android.app.Activity.performCreate(Activity.java:6955)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6776) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) 
add these dipendencies for java
implementation platform('com.google.firebase:firebase-bom:28.4.2')
implementation 'com.google.firebase:firebase-database'
for kotlin
implementation platform('com.google.firebase:firebase-bom:28.4.2')
implementation 'com.google.firebase:firebase-database-ktx'
then if using instance outside us1 for the database add url
FirebaseDatabase database = FirebaseDatabase.getInstance("**url here**);
DatabaseReference myRef = database.getReference("**path here**");

Spring WebFlux with OpenApi /Swagger Specification (Code Generation) File not Found

I already have the generated code in my spring webflux project, but when a run, its throw me an exception that "openapi.yaml" file does not exists. I searched this file and he is in the resource folder of the generated project(generated by openapi). As you can see, HomeController get this file with the classpath:/openapi.yaml in the Resource attribute declaration.
I'm just making this question because this is an error of a generated class, and i dont know if this should happen or not.
The resource declaration
#Value("classpath:/openapi.yaml")
private Resource openapi;
HomeController class
package org.openapitools.configuration;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.Charset;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
/**
* Home redirection to OpenAPI api documentation
*/
#Controller
public class HomeController {
private static YAMLMapper yamlMapper = new YAMLMapper();
#Value("classpath:/openapi.yaml")
private Resource openapi;
#Bean
public String openapiContent() throws IOException {
try(InputStream is = openapi.getInputStream()) {
return StreamUtils.copyToString(is, Charset.defaultCharset());
}
}
#GetMapping(value = "/openapi.yaml", produces = "application/vnd.oai.openapi")
#ResponseBody
public String openapiYaml() throws IOException {
return openapiContent();
}
#GetMapping(value = "/openapi.json", produces = "application/json")
#ResponseBody
public Object openapiJson() throws IOException {
return yamlMapper.readValue(openapiContent(), Object.class);
}
#Bean
RouterFunction<ServerResponse> index() {
return route(
GET("/"),
req -> ServerResponse.temporaryRedirect(URI.create("swagger-ui/index.html?url=../openapi.json")).build()
);
}
}
The error recivied.
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-16 00:23:12.728 ERROR 30601 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openapiContent' defined in class path resource [org/openapitools/configuration/HomeController.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.String]: Factory method 'openapiContent' threw exception; nested exception is java.io.FileNotFoundException: class path resource [openapi.yaml] cannot be opened because it does not exist
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:483) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:62) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at com.gabriel.forum.ForumApplication.main(ForumApplication.java:10) ~[main/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.String]: Factory method 'openapiContent' threw exception; nested exception is java.io.FileNotFoundException: class path resource [openapi.yaml] cannot be opened because it does not exist
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.String]: Factory method 'openapiContent' threw exception; nested exception is java.io.FileNotFoundException: class path resource [openapi.yaml] cannot be opened because it does not exist
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
... 20 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [openapi.yaml] cannot be opened because it does not exist
Caused by: java.io.FileNotFoundException: class path resource [openapi.yaml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) ~[spring-core-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.openapitools.configuration.HomeController.openapiContent(HomeController.java:36) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
... 21 common frames omitted
> Task :ForumApplication.main() FAILED
Execution failed for task ':ForumApplication.main()'.
> Process 'command '/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
The resource folder and the project structure.
I found a solution.
Just add a config option in your build.gralde or pom.xml "interfaceOnly": "true".
That configuration will generate only the interfaces and classes that you declared in the inputSpec file, and the HomeController will no longer exists to seek the openapi.yml file.
That solution is only for spring webflux projects.
Heres is the config options in gradle syntax:
configOptions = [
dateLibrary: "java8",
reactive: "true",
"interfaceOnly": "true"
]
Maven syntax:
<configOptions>
<reactive>true</reactive>
<java8>true</java8>
<interfaceOnly>true</interfaceOnly>
</configOptions>

IntelliJ form snapshot fails with exception

I created a simple project from scratch to test the form snapshot functionality.
The project has one source file and uses the defaults of File->New Project. The source is:
package com.company;
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
JLabel label = new JLabel("Hello");
JFrame frame = new JFrame("Title");
frame.setLayout(new BorderLayout());
frame.add(label,BorderLayout.CENTER);
frame.setSize(400,300);
frame.setVisible(true);
}
});
}
}
I get the following exception when I try to take a snap shot:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/intellij/designer/DesignerEditorPanelFacade
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.intellij.uiDesigner.radComponents.RadComponent.createSnapshotComponent(RadComponent.java:742)
at com.intellij.uiDesigner.radComponents.RadContainer.importSnapshotComponent(RadContainer.java:639)
at com.intellij.uiDesigner.radComponents.RadComponent.createSnapshotComponent(RadComponent.java:752)
at com.intellij.uiDesigner.snapShooter.SnapShooterDaemon$SuspendSwingRunnable.createFormSnapshot(SnapShooterDaemon.java:271)
at com.intellij.uiDesigner.snapShooter.SnapShooterDaemon$SuspendSwingRunnable.doSnapshotCommand(SnapShooterDaemon.java:259)
at com.intellij.uiDesigner.snapShooter.SnapShooterDaemon$SuspendSwingRunnable.run(SnapShooterDaemon.java:238)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.lang.ClassNotFoundException: com.intellij.designer.DesignerEditorPanelFacade
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 32 more
I checked the box for "Enable capturing form snapshots" in the run configuration.
When I go to New->Form Snapshot I get this window:
When I click "Create Snapshot" I get the exception I mentioned above.
Any ideas why this is happening? I have IDEA 14.1.4. I ran "Check for Updates" to be sure there wasn't anything new for IDEA or the plugins.
This is a bug in IntelliJ IDEA: https://youtrack.jetbrains.com/issue/IDEA-132891

Without sending calendar obj, it will work fine.. Then How to pass Calendar object from one activity to another?

we can pass String as
Intent returnIntent = new Intent();
returnIntent.putExtra("SelectedRadio", selectedRadio);
But if I want to pass Calendar object then how to pass it from one activity
to another?
Thanks in advance.
This is my First Activity:
public class MyCalendar extends Activity {
public Calendar myCal;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_calendar);
goCal= (ImageButton)findViewById(R.id.imageButton1);
myCal = Calendar.getInstance();
goCal.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MyCalendar.this, MainActivity.class);
i.putExtra("calendar", myCal);
startActivity(i);
});
}
}
This is my second Activity:
public class MainActivity extends Activity {
Intent myIntent;
Calendar today = (Calendar) myIntent.getExtras().getSerializable("calendar");
...
}
what is my fault. Why my app closed when i click goCal button. pls help me.. I am a new one..
my logcat:
01-09 18:55:50.338: W/dalvikvm(4252): threadid=1: thread exiting with uncaught exception (group=0xb5f41288)
01-09 18:55:50.338: E/AndroidRuntime(4252): FATAL EXCEPTION: main
01-09 18:55:50.338: E/AndroidRuntime(4252): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.mycalendar/com.example.mycalendar.MainActivity}: java.lang.NullPointerException
01-09 18:55:50.338: E/AndroidRuntime(4252): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
01-09 18:55:50.338: E/AndroidRuntime(4252): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-09 18:55:50.338: E/AndroidRuntime(4252): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-09 18:55:50.338: E/AndroidRuntime(4252): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-09 18:55:50.338: E/AndroidRuntime(4252): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 18:55:50.338: E/AndroidRuntime(4252): at android.os.Looper.loop(Looper.java:137)
01-09 18:55:50.338: E/AndroidRuntime(4252): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-09 18:55:50.338: E/AndroidRuntime(4252): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 18:55:50.338: E/AndroidRuntime(4252): at java.lang.reflect.Method.invoke(Method.java:511)
01-09 18:55:50.338: E/AndroidRuntime(4252): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-09 18:55:50.338: E/AndroidRuntime(4252): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-09 18:55:50.338: E/AndroidRuntime(4252): at dalvik.system.NativeStart.main(Native Method)
01-09 18:55:50.338: E/AndroidRuntime(4252): Caused by: java.lang.NullPointerException
01-09 18:55:50.338: E/AndroidRuntime(4252): at com.example.mycalendar.MainActivity.<init>(MainActivity.java:44)
01-09 18:55:50.338: E/AndroidRuntime(4252): at java.lang.Class.newInstanceImpl(Native Method)
01-09 18:55:50.338: E/AndroidRuntime(4252): at java.lang.Class.newInstance(Class.java:1319)
01-09 18:55:50.338: E/AndroidRuntime(4252): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
01-09 18:55:50.338: E/AndroidRuntime(4252): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
01-09 18:55:50.338: E/AndroidRuntime(4252): ... 11 more
Without sending calendar obj, it will work fine.. Then How to pass Calendar object from one activity to another?
we know Calander implements Serializable interface so, you can send it as a extra in the intent.
Intent i=new Intent(context,Home.class);
Calendar c=Calendar.getInstance();
i.putExtra("calobject", c);
startActivity(i);
and you can get it using this code
Calendar cal=(Calendar) getIntent().getSerializableExtra("calobject");
Here is the screenshot of debugged code it goes smoothly without any exception
I hope this will help you
Since Calendar implements Serializable you can simply do the following:
Calendar cal;
<calendar initialization>
intent.putExtra("calendar", cal);
Then for retrieving:
Calendar cal;
cal = (Calendar) intent.getSerializableExtra("calendar");