Why does this function fail at runtime? - runtime

I have the following piece of code, why does it fail at runtime?
Code from MainActivity:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainuilayout_fragment);
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
home_directory = mPrefs.getString("home_directory", home_directory);
JNIdc.config(home_directory);
This is the error that I get
2020-02-27 13:08:35.997 19527-19527/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.emulator, PID: 19527
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data``/app/com.android.emulator-DSqX_PGjDkqsKqoajwOoYw==/base.apk"],nativeLibraryDirectories=[/data/app/com.android.emulator-DSqX_PGjDkqsKqoajwOoYw==/lib/arm64, /system/lib64, /vendor/lib64]]] couldn't find "libdc.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
at java.lang.System.loadLibrary(System.java:1657)
at com.android.emulator.JNIdc.<clinit>(JNIdc.java:6)
at com.android.emulator.JNIdc.config(Native Method)
at com.android.emulator.MainActivity.onCreate(MainActivity.java:67)
at android.app.Activity.performCreate(Activity.java:7028)
at android.app.Activity.performCreate(Activity.java:7019)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2808)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2933)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1627)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:6722)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
Why do I get this error?

I believe that libdc.so is missing. It needs to be added first before it recognizes JNIdc.config. I receive an error when I try to solve the line for android.mk before running ndk-build. It says
/home/user/Desktop/project/app/shell/android/jni/Android.mk:21: /home/user/Desktop/project/app/shell/android/jni/../../core/core.mk: No such file or directory
make: *** No rule to make target '/home/user/Desktop/project/app/shell/android/jni/../../core/core.mk'. Stop.

Related

How to fix duplicate symbol error in compiling simple module inheriting INET EtherTrafGen class in omnet++?

I try to make my own traffic generator module inheriting INET EtherTrafGen in omnet++,
only resulting in duplicate symbol error. I can't figure out the reason.
Below are the compile error messages.
..
Creating executable: ../out/clang-release/src/hdc.exe
lld-link: error: duplicate symbol: inet::OperationalMixin<omnetpp::cSimpleModule>::isUp() const
>>> defined at ../out/clang-release/src/TrafGen.o
>>> defined at libINET.dll
lld-link: error: duplicate symbol: inet::OperationalMixin<omnetpp::cSimpleModule>::isDown() const
>>> defined at ../out/clang-release/src/TrafGen.o
>>> defined at libINET.dll
clang++: error: linker command failed with exit code 1 (use -v to see invocation
..
The corresponding header file, i.e. TrafGen.h is
#include "inet/applications/ethernet/EtherTrafGen.h"
namespace inet {
//class TrafGen : public cSimpleModule ----> In this case, no compile error
class TrafGen : public EtherTrafGen
{
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
}
and the corresponding TrafGen.cc file is
#include "TrafGen.h"
namespace inet {
Define_Module(TrafGen);
void TrafGen::initialize()
{
if (strcmp("hostA", getName()) == 0) {
cMessage *msg = new cMessage("hdcMsg");
send(msg, "out");
}
}
void TrafGen::handleMessage(cMessage *msg)
{
send(msg, "out"); // send out the message
}
}
TrafGen.ned is
import inet.applications.ethernet.EtherTrafGen;
simple TrafGen extends EtherTrafGen
{
parameters:
#class(inet::TrafGen);
}
By the way, when the TrafGen: public 'cSimpleModule' is used instead of 'EtherTrafGen' in the definition of TrafGen in the TrafGen.h, no compile error (duplicate symbol error) occurs.
I changed the PREFER_CLANG of configure.user file as 'no'. Now it seems that the duplicate symbol errors do not occur.

Using a when clause in an enum class getter in Kotlin

I'm trying to get a specific getter of a property in kotlin to be based on the value of the enum it is called from. This is what I got so far:
enum class Endpoint {
EVENTS, GAMES;
val baseUrl = "https://www.example.com/api"
val path: String
get() = when(this){
EVENTS -> "$baseUrl/events"
GAMES -> "$baseUrl/games"
}
}
Called like this:
print(Endpoint.EVENTS.path)
While this compiles without any problem, as soon as I run it I get a NullPointerException with the error Attempt to invoke virtual method 'java.lang.Object [...].Endpoint[].clone()' on a null object reference
I'm not sure what I'm doing wrong or what the proper way to accomplish what is stated above is.
EDIT: Full log of the exception:
05-09 22:51:33.793 15673-15673/com.filippovigani.eventvods E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.filippovigani.eventvods, PID: 15673
java.lang.ExceptionInInitializerError
at com.filippovigani.eventvods.networking.Endpoint.getPath(Endpoint.kt:21)
at com.filippovigani.eventvods.networking.Endpoint.<init>(Endpoint.kt:25)
at com.filippovigani.eventvods.networking.Endpoint.<clinit>(Endpoint.kt)
at com.filippovigani.eventvods.networking.EventvodsApi$Companion.getEvents(EventvodsApi.kt:8)
at com.filippovigani.eventvods.MainActivity.onCreate(MainActivity.kt:19)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object com.filippovigani.eventvods.networking.Endpoint[].clone()' on a null object reference
at com.filippovigani.eventvods.networking.Endpoint.values(Endpoint.kt)
at com.filippovigani.eventvods.networking.Endpoint$WhenMappings.<clinit>(Unknown Source)
at com.filippovigani.eventvods.networking.Endpoint.getPath(Endpoint.kt:21) 
at com.filippovigani.eventvods.networking.Endpoint.<init>(Endpoint.kt:25) 
at com.filippovigani.eventvods.networking.Endpoint.<clinit>(Endpoint.kt) 
at com.filippovigani.eventvods.networking.EventvodsApi$Companion.getEvents(EventvodsApi.kt:8) 
at com.filippovigani.eventvods.MainActivity.onCreate(MainActivity.kt:19) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
I can't reproduce your error, the code works fine. Nevertheless, I think the solution is a bit too complex, why don't you use a constructor argument to provide the constant-specific value:
enum class Endpoint(service: String) {
EVENTS("/events"), GAMES("/games");
private val baseUrl = "https://www.example.com/api"
val path: String = baseUrl + service
}
The exception indicates you're trying to access path within the constructor of the enum. This causes a problem because the enum is not yet ready for use during construction.
This means the following chain of calls results in failure:
Init Endpoint
Init Endpoint.EVENTS
Call to Endpoint.getPath() (This does not show in your code)
Uses Endpoint$WhenMapping, begin init of that class.
Endpoint$WhenMapping uses EndPoint.values(), but since we're still initializing the instances of the enum, the values array cannot be provided, returning null.
To ensure it is not modified, WhenMapping clones and caches the array, but since the array is null when it never should be outside of initialization this causes the NPE.
Simply put your code somehow relies on a class that requires itself to be fully initialized to use. Since your code does not display how you're calling Endpoint.EVENTS.path this is all that can be said about it.

A generic internal error page should be shown when an unexpected exception is thrown in wicket6.x or wicket7.7?

protected void init() {
getApplicationSettings().setInternalErrorPage(BnafInternalErrorPage.class);
getApplicationSettings().setPageExpiredErrorPage(BnafAccessDeniedErrorPage.class);
getApplicationSettings().setAccessDeniedPage(BnafAccessDeniedErrorPage.class);
getExceptionSettings().setInternalErrorPage(IExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);
In above code i got error at IExceptionSettings.
IExceptionSettings removed in wicket 7
So you can replace this below line.
getExceptionSettings().setInternalErrorPage(IExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);
to
getExceptionSettings().setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);
To know more details check here
https://cwiki.apache.org/confluence/display/WICKET/Migration+to+Wicket+7.0#MigrationtoWicket7.0-AllIXyzSettingsareremovedWICKET-5410

startRecording() called on an uninitialized AudioRecord?

I have below code that gives init failure:
recorder = new AudioRecord(AudioSource.MIC, mSamplingRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, iN);
recorder.startRecording();
It's called by my Activity:
new AsyncTask<Void, Void, Void>(){
#Override
protected Void doInBackground(Void... none) {
record();
return null;
}
}.execute();
It gives below exception:
E/AudioRecord: AudioFlinger could not create record track, status: -1
E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
E/AudioRecord: AudioFlinger could not create record track, status: -1
E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
What could have gone wrong, please?
I believe it's not the problem of the audio recorder, but about async task/ multithreading. Because it works like charm before when I had a fragment including an onCreateView, and I put the AsyncTask call in onClick of a button.
Now I initial the UI in my activity's OnCreate(), I don't have fragment or onCreateView, I thought I'm already using a async thread but still...
Solved - repushing the apk from Android Studio after changing the permissions in the manifest doesn't actually change the permission in the app settings.
I have to manually open Settings ->> App -> Permissions -> slide "Microphone to be on.

Integrating CKEditor with SmartGWT

I tried to integrate CKEditor in a SmartGWT application using the gwt-ckeditor module. But I get an error when I try to display the application, in dev-mode:
[ERROR] [Eureka] - 18:21:15.139:TMR5[E]:WARN:drawing:campaignMessageDesignPage_id:draw() called on widget with current drawn state: handleDrawn, ignoring.
Class.getStackTrace(_1=>undef, _2=>undef, _3=>undef, _4=>undef)
Canvas.readyToDraw()
Canvas.draw(_1=>undef)
Layout.layoutChildren(_1=>"resized", _2=>0, _3=>19)
Canvas.$t1()
Canvas.resizeBy(_1=>0, _2=>19, _3=>undef, _4=>undef)
Canvas.resizeTo(_1=>1365, _2=>586, _3=>undef, _4=>undef)
Layout.resizeMembers(_1=>Array[12], _2=>Array[12], _3=>true)
** recursed on Layout.layoutChildren
com.smartgwt.client.core.JsObject$SGWT_WARN: 10:35:18.045:TMR7[E]:WARN:drawing:campaignMessageDesignPage_id:draw() called on widget with current drawn state: handleDrawn, ignoring.
Class.getStackTrace(_1=>undef, _2=>undef, _3=>undef, _4=>undef) Canvas.readyToDraw() Canvas.draw(_1=>undef) Layout.layoutChildren(_1=>"resized", _2=>0, _3=>19) Canvas.$t1() Canvas.resizeBy(_1=>0, _2=>19, _3=>undef, _4=>undef) Canvas.resizeTo(_1=>1365, _2=>586, _3=>undef, _4=>undef) Layout.resizeMembers(_1=>Array[12], _2=>Array[12], _3=>true) ** recursed on Layout.layoutChildren
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:722)
Here a piece of my code:
public class CampaignMessageDesignPage extends Page {
protected VLayout mainLayout;
protected CKEditor ckEditor;
#Override
protected void prepareMainLayoutCanvasCandidate() {
mainLayout = createOrGetVLayoutById(campaignMessageDesignPage_id);
mainLayout.setWidth100();
mainLayout.setHeight100();
mainLayout.setDefaultLayoutAlign(Alignment.CENTER);
Canvas cnvEditor = new Canvas("cnvEditor");
CKConfig conf = new CKConfig(PRESET_TOOLBAR.FULL);
ckEditor = new CKEditor(conf);
conf.setBaseFloatZIndex(1000000);
conf.setUseFormPanel(false);
ckEditor.setHTML("");
ckEditor.setSize("100%", "100%");
cnvEditor.addChild(ckEditor);
cnvEditor.setSize("50%", "50%");
mainLayout.setMembers(cnvEditor);
}
#Override
protected final Canvas getMainLayoutCanvasCandidate() {
return this.mainLayout;
}
#Override
protected void process(final SimpleBO param) {
// TODO Auto-generated method stub
}
}
The draw() method is called elsewhere.
Do you have any idea?
Edit:
I tried some different stuff. I tried to add standard GWT widgets to my SmartGWT layout and it worked fine, so it's really a CKEditor related problem.
I also tried to create the content on page display, and obtained another error message, hopefully more useful:
18:45:06.698 [ERROR] [Eureka] 18:45:06.697:RDQ0[E]:WARN:Log:TypeError: Cannot call method 'replace' of undefined
unnamed() #
unnamed() # unknown source
unnamed() # Eureka/hosted.html?Eureka:76:35
unnamed() # Eureka/hosted.html?Eureka:54:12
onDraw() # unknown source
Canvas.draw() # Eureka/sc/modules/ISC_Core.js:2123:6
Canvas.drawChildren() # Eureka/sc/modules/ISC_Core.js:2177:197
Canvas.draw() # Eureka/sc/modules/ISC_Core.js:2114:247
Layout._drawNonMemberChildren() # Eureka/sc/modules/ISC_Foundation.js:374:21
Layout.drawChildren() # Eureka/sc/modules/ISC_Foundation.js:365:130
Canvas.draw() # Eureka/sc/modules/ISC_Core.js:2114:247
com.smartgwt.client.core.JsObject$SGWT_WARN: 18:45:06.697:RDQ0[E]:WARN:Log:TypeError: Cannot call method 'replace' of undefined
unnamed() #
unnamed() # unknown source
unnamed() # Eureka/hosted.html?Eureka:76:35
unnamed() # Eureka/hosted.html?Eureka:54:12
onDraw() # unknown source
Canvas.draw() # Eureka/sc/modules/ISC_Core.js:2123:6
Canvas.drawChildren() # Eureka/sc/modules/ISC_Core.js:2177:197
Canvas.draw() # Eureka/sc/modules/ISC_Core.js:2114:247
Layout._drawNonMemberChildren() # Eureka/sc/modules/ISC_Foundation.js:374:21
Layout.drawChildren() # Eureka/sc/modules/ISC_Foundation.js:365:130
Canvas.draw() # Eureka/sc/modules/ISC_Core.js:2114:247
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:722)
There's a component that does this for you in the SmartGWT-Extensions Google Code project:
http://code.google.com/p/smartgwt-extensions/source/browse/#svn%2Ftrunk%2Fmainprojects%2Fsrc%2Fmain%2Fjava%2Fcom%2Fsmartgwt%2Fextensions%2Fhtmleditor%2Fclient

Resources