So I have an app which writes sensor data to a csv file via FileOutputStream in MODE_PRIVATE
FileOutputStream fos = null;
try {
fos = context.openFileOutput(FILE_NAME,Context.MODE_PRIVATE);
for(int i = 0; i< signalList.size(); i++){
Signal s = signalList.get(i);
fos.write(s.toString().getBytes());
}
Log.d("WRITESTATUS","Success");
}
Now I wanted to share this file with other apps (whatsapp,email etc.). To achieve that, I am using the code below to share the intent. I was trying to use MODE_WORLD..something but that didn't work because it was deprecated so I learned through the other stackoverflow questions that we need to use FileProvider to make that happen but that didn't work either.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/*");
File file = getFileStreamPath(FILE_NAME);
Uri uri = FileProvider.getUriForFile(this,"com.example.writefile",file);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(sharingIntent, "Share SENSOR Data"));
<provider
android:authorities="com.example.writefile"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_path"/>
</provider>
ERROR LOG
2020-06-22 16:27:34.047 6578-6578/? E/ample.writefil: Unknown bits set in runtime_flags: 0x8000
2020-06-22 16:27:34.147 6578-6578/com.example.writefile E/libc: Access denied finding property "vendor.iop.enable_uxe"
2020-06-22 16:27:36.043 6578-6578/com.example.writefile E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.writefile, PID: 6578
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:402)
at android.view.View.performClick(View.java:7158)
at android.view.View.performClickInternal(View.java:7135)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27373)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:235)
at android.app.ActivityThread.main(ActivityThread.java:7441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:7158)
at android.view.View.performClickInternal(View.java:7135)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27373)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:235)
at android.app.ActivityThread.main(ActivityThread.java:7441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.writefile/files/sensor.csv
at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:744)
at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:418)
at com.example.writefile.MainActivity.Clicked(MainActivity.java:266)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:7158)
at android.view.View.performClickInternal(View.java:7135)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27373)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:235)
at android.app.ActivityThread.main(ActivityThread.java:7441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Change this and it will work- I have taken hint from here and tried different configuration and this works, I don't know why.
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
name="sensor"
path="."/>
</paths>
I'm using WSO2 APIManager 1.10.
I'd like to call api request using mediation like this.
<sequence name="loadbalancer_bycompany" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="get-property('transport', 'company')"
name="company" scope="default" type="STRING"/>
<property name="POST_TO_URI" scope="axis2" type="STRING" value="true"/>
<switch source="$trp:company">
<case regex="sds">
<send>
<endpoint>
<address trace="disable" uri="https://70.30.182.167:8243/calc/1.0/"/>
</endpoint>
</send>
</case>
<case regex="etc">
<send>
<endpoint>
<address trace="disable" uri="https://70.30.182.167:9443/calc/1.0/"/>
</endpoint>
</send>
</case>
<default>
<send>
<endpoint>
<address trace="disable" uri="https://70.30.182.167:9443/carbon/"/>
</endpoint>
</send>
</default>
</switch>
</sequence>
So,I tried to set mediator and then i called api.
But, I got sometimes error response that is code 900902 missing credential,
sometimes got right response.
At that time, I found logs like this.
TID: [-1234] [] [2017-02-03 10:45:10,728] INFO {org.apache.synapse.mediators.builtin.LogMediator} - STATUS = Executing default 'fault' sequence, ERROR_CODE = 0, ERROR_MESSAGE = Access-Control-Allow-Headers:authorization,Access-Control-Allow-Origin,Content-Type,company,Access-Control-Allow-Methods:GET,Access-Control-Allow-Origin:*,<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope> Unexpected error sending message back {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2017-02-03 10:45:10,735] ERROR {org.apache.synapse.transport.passthru.PassThroughHttpSSLSender} - Failed to submit the response {org.apache.synapse.transport.passthru.PassThroughHttpSSLSender}
java.lang.NullPointerException
at org.apache.synapse.transport.passthru.util.SourceResponseFactory.create(SourceResponseFactory.java:64)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.submitResponse(PassThroughHttpSender.java:462)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:267)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:212)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:493)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:108)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:155)
at org.apache.synapse.mediators.MediatorFaultHandler.onFault(MediatorFaultHandler.java:86)
at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:102)
at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:108)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:534)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:172)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:251)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
TID: [-1234] [] [2017-02-03 10:45:10,738] ERROR {org.apache.synapse.core.axis2.Axis2Sender} - Access-Control-Allow-Headers:authorization,Access-Control-Allow-Origin,Content-Type,company,Access-Control-Allow-Methods:GET,Access-Control-Allow-Origin:*,<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><am:fault xmlns:am="http://wso2.org/apimanager"><am:code>0</am:code><am:type>Status report</am:type><am:message>Runtime Error</am:message><am:description>Access-Control-Allow-Headers:authorization,Access-Control-Allow-Origin,Content-Type,company,Access-Control-Allow-Methods:GET,Access-Control-Allow-Origin:*,<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope> Unexpected error sending message back</am:description></am:fault></soapenv:Body></soapenv:Envelope> Unexpected error sending message back {org.apache.synapse.core.axis2.Axis2Sender}
org.apache.axis2.AxisFault: Failed to submit the response
at org.apache.synapse.transport.passthru.PassThroughHttpSender.handleException(PassThroughHttpSender.java:610)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:269)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:212)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:493)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:108)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:155)
at org.apache.synapse.mediators.MediatorFaultHandler.onFault(MediatorFaultHandler.java:86)
at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:102)
at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:108)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:534)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:172)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:251)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.apache.synapse.transport.passthru.util.SourceResponseFactory.create(SourceResponseFactory.java:64)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.submitResponse(PassThroughHttpSender.java:462)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:267)
... 18 more
TID: [-1234] [] [2017-02-03 10:45:10,740] ERROR {org.apache.axis2.transport.base.threads.NativeWorkerPool} - Uncaught exception {org.apache.axis2.transport.base.threads.NativeWorkerPool}
java.lang.RuntimeException: org.apache.synapse.SynapseException: Access-Control-Allow-Headers:authorization,Access-Control-Allow-Origin,Content-Type,company,Access-Control-Allow-Methods:GET,Access-Control-Allow-Origin:*,<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><am:fault xmlns:am="http://wso2.org/apimanager"><am:code>0</am:code><am:type>Status report</am:type><am:message>Runtime Error</am:message><am:description>Access-Control-Allow-Headers:authorization,Access-Control-Allow-Origin,Content-Type,company,Access-Control-Allow-Methods:GET,Access-Control-Allow-Origin:*,<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope> Unexpected error sending message back</am:description></am:fault></soapenv:Body></soapenv:Envelope> Unexpected error sending message back
at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:110)
at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:108)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:534)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:172)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:251)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.synapse.SynapseException: Access-Control-Allow-Headers:authorization,Access-Control-Allow-Origin,Content-Type,company,Access-Control-Allow-Methods:GET,Access-Control-Allow-Origin:*,<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><am:fault xmlns:am="http://wso2.org/apimanager"><am:code>0</am:code><am:type>Status report</am:type><am:message>Runtime Error</am:message><am:description>Access-Control-Allow-Headers:authorization,Access-Control-Allow-Origin,Content-Type,company,Access-Control-Allow-Methods:GET,Access-Control-Allow-Origin:*,<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope> Unexpected error sending message back</am:description></am:fault></soapenv:Body></soapenv:Envelope> Unexpected error sending message back
at org.apache.synapse.core.axis2.Axis2Sender.handleException(Axis2Sender.java:247)
at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:215)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:493)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:108)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:155)
at org.apache.synapse.mediators.MediatorFaultHandler.onFault(MediatorFaultHandler.java:86)
at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:102)
... 9 more
Caused by: org.apache.axis2.AxisFault: Failed to submit the response
at org.apache.synapse.transport.passthru.PassThroughHttpSender.handleException(PassThroughHttpSender.java:610)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:269)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:212)
... 16 more
Caused by: java.lang.NullPointerException
at org.apache.synapse.transport.passthru.util.SourceResponseFactory.create(SourceResponseFactory.java:64)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.submitResponse(PassThroughHttpSender.java:462)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:267)
... 18 more
TID: [-1234] [] [2017-02-03 10:45:59,370] INFO {org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler} - Stat is not enabled {org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler}
TID: [-1234] [] [2017-02-03 10:45:59,374] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /calc/1.0/subtract?x=3&y=1, MessageID: urn:uuid:8f4000dc-b878-4d5f-b310-f0129f2db0a3, Direction: request, INFO = https://70.30.182.167:8243/calc/1.0/, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2017-02-03 10:45:59,390] INFO {org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler} - Stat is not enabled {org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler}
TID: [-1234] [] [2017-02-03 10:45:59,395] WARN {org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler} - API authentication failure due to Missing Credentials {org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler}
I found this logs repeatedly, so I i made an effort to fix it.
First of all, to remove this error,
NullPointerException
SourceResponseFactory.create(SourceResponseFactory.java:64)
I figured out code issue in PassThroughHttpSender.java that didn't handle with null case for sourceRequest. And then I found that issue was fixed
wso2-synapse
ESBJAVA-3770 Message size based filtering to prevent OOM. (#679)
https://github.com/wso2/wso2-synapse/commit/1aff92c4bad968f78cf38577cbb7c01516475217
So, I added that code into our codes.
And then NullPointException was disappeared.
And then I tried to remove missing credential error.
So I found this link.
Authorization Bearer in URL Request using WSO2 API Manager
And I tried to set configure like below link.
https://docs.wso2.com/display/AM1100/Writing+Custom+Handlers
And then Missing credential error was removed.
And then result is right response.
But I found below log infinitely
TID: [-1234] [] [2017-02-08 13:20:12,563] WARN {org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler} - No authentication context information found on the request - Throttling not applied {org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler}
I tried to debug SourceHandler and TargetHandler.
and I think connection was created infinitely and wasn't closed all.
I don't know what to do anymore.
So please let me know what I have to do.
Please go through the sample implementation provided in docs. Based on the APIThrottleHandler implementation, this warning message would appear if you haven't set the user context within your custom Auth handler. Please check how the default "OAuthAuthenticator" has been written and how the AuthenticationContext getting initialized. You need to do a similar implementation to your custom handler if need to work with throttling.
How can I attach a Fragment to an Activity with AndroidAnnotations?
I have a Activity with a layout XML. I also have a Fragment with a layout XML.
How do I connect the Fragment to the Activity? The Fragment and its content/layout should be displayed inside the <fragment ...> tag of the Activity layout XML file.
Here are my classes and their respective XML layouts (trimmed down for better readability):
#EActivity(R.layout.activity_add_contact)
public class AddContactActivity extends AppCompatActivity {
private final String TAG = getClass().getSimpleName();
#FragmentById(R.id.add_contact_fragment)
AddContactFragment addContactFragment;
#Extra
String contactName;
#ViewById(R.id.toolbar)
Toolbar toolbar;
#AfterViews
void createView() {
setSupportActionBar(toolbar);
setTitle(getString(R.string.new_contact_title, contactName.trim()));
}
}
actvitiy_add_contact.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".AddContactActivity_">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<fragment
android:id="#+id/add_contact_fragment"
android:name="net.gazeapp.AddContactFragment_"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</android.support.design.widget.CoordinatorLayout>
And here is the Fragment:
#EFragment(R.layout.fragment_add_contact)
public class AddContactFragment extends Fragment implements DatePickerDialog.OnDateSetListener {
private final String TAG = getClass().getSimpleName();
#ViewById(R.id.nickname)
EditText nickname;
#ViewById(R.id.birthdate)
EditText birthdate;
public AddContactFragment() {
}
#AfterViews
public void onCreateView() {
// Hide Keyboard initially
getActivity().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
);
}
}
and its XML layout:
fragment_add_contact.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:overScrollMode="never"
android:theme="#style/MyEditTextTheme">
<!-- FRAGMENT LAYOUT / INPUT FIELDS ETC -->
</ScrollView>
It is unclear to me how I can get the Fragment into the <fragment> tag in the Activity. When I run it with the code above I get this error message:
02-22 21:26:05.689 16267-16267/net.gazeapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.gazeapp, PID: 16267
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.gazeapp/net.gazeapp.AddContactActivity_}: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at net.gazeapp.AddContactActivity_.setContentView(AddContactActivity_.java:55)
at net.gazeapp.AddContactActivity_.onCreate(AddContactActivity_.java:44)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at net.gazeapp.AddContactActivity_.setContentView(AddContactActivity_.java:55)
at net.gazeapp.AddContactActivity_.onCreate(AddContactActivity_.java:44)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassCastException: net.gazeapp.AddContactActivity_#cba10e4 must implement MyListFragment.OnContactObjectChangedListener
at net.gazeapp.AddContactFragment.onAttach(AddContactFragment.java:161)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1019)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1226)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1328)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2284)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:314)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at net.gazeapp.AddContactActivity_.setContentView(AddContactActivity_.java:55)
at net.gazeapp.AddContactActivity_.onCreate(AddContactActivity_.java:44)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Thanks for any help.
The problem lies here:
Caused by: java.lang.ClassCastException: net.gazeapp.AddContactActivity_#cba10e4 must implement MyListFragment.OnContactObjectChangedListener
at net.gazeapp.AddContactFragment.onAttach(AddContactFragment.java:161)
You did not share AddContactFragment.onAttach() method in your question, but it seems you are casting the Activity to an OnContactObjectChangedListener. However, the Activity is not implementing that interface, that is why you are getting this exception.
I got a generatorConfig.xml like this:
<generatorConfiguration>
<classPathEntry location="D:\Workspace\springlt\src\main\resources\ojdbc6.jar" />
<context id="MyBatis3" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="myurl" userId="username"
password="password">
</jdbcConnection>
<javaModelGenerator targetPackage="vn.laptrinh.domain"
targetProject="../java" />
<sqlMapGenerator targetPackage="vn.laptrinh.dao.xml"
targetProject="../java" />
<javaClientGenerator type="XMLMAPPER"
targetPackage="vn.laptrinh.dao" targetProject="../java" />
<!-- <table tableName="users" domainObjectName="User"
enableSelectByExample="false" enableDeleteByExample="false"
enableCountByExample="false" enableUpdateByExample="false">
<columnOverride column="id" javaType="Long" />
</table> -->
<table tableName="CARDUSER_MASTER" domainObjectName="CardUserMaster"
schema="CACISISS" enableSelectByExample="false"
enableDeleteByExample="false" enableCountByExample="false"
enableUpdateByExample="false">
</table>
</context>
</generatorConfiguration>
Previously, I use mysql database and I put mysql-connector-java-5.1.15-bin.jar and mybatis-generator-core-1.3.1.jar in ..\springlt\src\main\resources folder, then use command line to run java -jar mybatis-generator-core-1.3.1.jar -configfile generatorConfig.xml -overwrite -tables users, project will generate domain, xml, xmlmapper
However when I change mysql-connector-java-5.1.15-bin.jar to ojdbc6.jar (I'm using oracle 11g), then I run and got bunches of errors:
D:\Workspace\springlt\src\main\resources>java -jar mybatis-generator-core-1.3.1.
jar -configfile generatorConfig.xml
Exception in thread "main" java.lang.RuntimeException: Exception getting JDBC Dr
iver
at org.mybatis.generator.internal.db.ConnectionFactory.getDriver(Connect
ionFactory.java:85)
at org.mybatis.generator.internal.db.ConnectionFactory.getConnection(Con
nectionFactory.java:54)
at org.mybatis.generator.config.Context.getConnection(Context.java:498)
at org.mybatis.generator.config.Context.introspectTables(Context.java:40
8)
at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.
java:221)
at org.mybatis.generator.api.ShellRunner.main(ShellRunner.java:117)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.mybatis.generator.internal.ObjectFactory.externalClassForName(Obj
ectFactory.java:90)
at org.mybatis.generator.internal.db.ConnectionFactory.getDriver(Connect
ionFactory.java:82)
... 5 more
I dont' know what is the problem is. I connect to database located on server.
Any solutions would be appreciated. Thanks.
Firstly, please change this:
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="myurl" userId="username"
password="password">
</jdbcConnection>
to
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="myurl" userId="username"
password="password">
</jdbcConnection>
and see if it is working for you
I had everything configured properly and realised the cause of this error can also be that the plugin is not able to find the ojdbc jar. What worked for me is to add classPathEntry in my generator file.
<generatorConfiguration>
<classPathEntry location="/Users/adaprognotebook/lib/ojdbc6.jar"/>
<context id="system" >
<plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" />
...
Hi I'm trying to test my dao layer with junit, and here is the file structure:
project
*src
main
java
resources
META-INF
persistence.xml
webapp
WEB-INF
applicationContext.xml
web.xml
test
java
resources
testingContext.xml
test-persistence.xml
jdbc.properties
Here is the test cases that I created for my project:
#ContextConfiguration({ "/testingContext.xml" })
#RunWith(SpringJUnit4ClassRunner.class)
public abstract class AbstractDaoForTesting extends AbstractTransactionalJUnit4SpringContextTests {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
#Autowired(required = true)
protected ...
}
And a single test case as follow :
public class MyDaoTest extends AbstractDaoForTesting {
#Test
public void testFind(){}
...
}
Here is the content of testingContext file which is quite similar to my applicationContext
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="classpath:jdbc.properties" />
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"
/>
<bean id="loadTimeWeaver" class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"
p:showSql="true"
p:databasePlatform="org.eclipse.persistence.platform.database.MySQLPlatform" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="myDataSource"
p:jpaVendorAdapter-ref="jpaVendorAdapter"
p:persistenceXmlLocation="classpath:test-persistence.xml"
/>
<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:dataSource-ref="tttDataSource"
p:entityManagerFactory-ref="entityManagerFactory"/>
<!-- checks for annotated configured beans -->
<context:annotation-config/>
<!-- Scan for Repository/Service annotations -->
<context:component-scan base-package="com.blah.dao" />
<context:component-scan base-package="com.blah.service" />
<context:component-scan base-package="com.blah.web" />
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven />
</beans>
the build fails because of he test and I get BeanDefinitionStore Exception. I have read many similar items here but I still have the problem. I added #WebAppConfiguration on my test classes but it didn't solve it.
I have to mention that I have used configuration classes to configure Spring MVC as follow
#EnableWebMvc
#Configuration
#ComponentScan("com.blab.web")
public class WebAppConfig extends WebMvcConfigurerAdapter {}
Here is the exception :
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener#a0b6fa] to prepare test instance [com.gieman.tttracker.service.CompanyServiceTest#1bc9a8d]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:331)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:292)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:159)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:87)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.HandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping()] threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 31 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.HandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping()] threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
... 48 more
Caused by: java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer.<init>(DefaultServletHandlerConfigurer.java:54)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping(WebMvcConfigurationSupport.java:346)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$7245b7bf.CGLIB$defaultServletHandlerMapping$26(<generated>)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$7245b7bf$$FastClassBySpringCGLIB$$a898995d.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$7245b7bf.defaultServletHandlerMapping(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 49 more
Thanks in advance for your help.
You should check com.gieman.tttracker.service.CompanyServiceTest, the error is :
A ServletContext is required to configure default servlet handling
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:597)
may implements ServletContextAware cause this problem.