how to connect android studio to mysql with jdbc - android

I've downloaded mysql-java-connector-5.1
and import it as library
the program is being compiled but no matter what i'm doing an exception is being thrown about connection failure.
i want to send data from the app(android studio-java) to sql data base which is stored in amazon(aws) and i want to get the data with raspberry pi(with c++).
the c++ works perfect.
with the android studio i canot connect, no to local host(mysql workbench) and not to aws.
i saw few templates on the web for the "url" parameter int the "getConnection" function, i used those:
for local host:
String url = "jdbc:mysql://<local ip>:<port>/<schema>
for aws:
String url = "jdbc:mysql://<endpoint given by aws>:<port>/<schema>
none of them work please help
this is my code:
public void test(View view) {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
String url = "jdbc:mysql://192.168.1.17:3306/sys";
String user = "root";
String password = "password";
//local verion - find ip with ifconfig/what is my ip website
conn = DriverManager.getConnection(url, user, password);
// Do something with the Connection
} catch (SQLException ex) {
// handle any errors
Log.i("SQLException: " , ex.getMessage());
Log.i("SQLState: " , ex.getSQLState());
}
but conn always null.
did i forget something?
* by the way im not sure if i have to use the
Class.forName("com.mysql.jdbc.Driver").newInstance();
but i used it anyway.
this is the printStackTrace results:
System.err: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
08-10 19:26:58.223 20891-20891/com.example.asaf.sql W/System.err: at java.lang.reflect.Constructor.newInstance0(Native Method)
08-10 19:26:58.225 20891-20891/com.example.asaf.sql W/System.err: at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
08-10 19:26:58.227 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
08-10 19:26:58.228 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.Util.getInstance(Util.java:408)
08-10 19:26:58.230 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
08-10 19:26:58.232 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
08-10 19:26:58.234 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
08-10 19:26:58.235 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
08-10 19:26:58.238 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2267)
08-10 19:26:58.240 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2016)
08-10 19:26:58.241 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:776)
08-10 19:26:58.243 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
08-10 19:26:58.244 20891-20891/com.example.asaf.sql W/System.err: at java.lang.reflect.Constructor.newInstance0(Native Method)
08-10 19:26:58.245 20891-20891/com.example.asaf.sql W/System.err: at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
08-10 19:26:58.247 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
08-10 19:26:58.248 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
08-10 19:26:58.250 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
08-10 19:26:58.251 20891-20891/com.example.asaf.sql W/System.err: at java.sql.DriverManager.getConnection(DriverManager.java:569)
08-10 19:26:58.252 20891-20891/com.example.asaf.sql W/System.err: at java.sql.DriverManager.getConnection(DriverManager.java:219)
08-10 19:26:58.254 20891-20891/com.example.asaf.sql W/System.err: at com.example.asaf.sql.MainActivity.test(MainActivity.java:45)
08-10 19:26:58.255 20891-20891/com.example.asaf.sql W/System.err: at java.lang.reflect.Method.invoke(Native Method)
08-10 19:26:58.257 20891-20891/com.example.asaf.sql W/System.err: at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
08-10 19:26:58.258 20891-20891/com.example.asaf.sql W/System.err: at android.view.View.performClick(View.java:5637)
08-10 19:26:58.259 20891-20891/com.example.asaf.sql W/System.err: at android.view.View$PerformClick.run(View.java:22429)
08-10 19:26:58.260 20891-20891/com.example.asaf.sql W/System.err: at android.os.Handler.handleCallback(Handler.java:751)
08-10 19:26:58.262 20891-20891/com.example.asaf.sql W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
08-10 19:26:58.263 20891-20891/com.example.asaf.sql W/System.err: at android.os.Looper.loop(Looper.java:154)
08-10 19:26:58.265 20891-20891/com.example.asaf.sql W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6119)
08-10 19:26:58.266 20891-20891/com.example.asaf.sql W/System.err: at java.lang.reflect.Method.invoke(Native Method)
08-10 19:26:58.267 20891-20891/com.example.asaf.sql W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
08-10 19:26:58.269 20891-20891/com.example.asaf.sql W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
08-10 19:26:58.272 20891-20891/com.example.asaf.sql W/System.err: Caused by: android.os.NetworkOnMainThreadException
08-10 19:26:58.273 20891-20891/com.example.asaf.sql W/System.err: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)
08-10 19:26:58.273 20891-20891/com.example.asaf.sql W/System.err: at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:86)
08-10 19:26:58.274 20891-20891/com.example.asaf.sql W/System.err: at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74)
08-10 19:26:58.275 20891-20891/com.example.asaf.sql W/System.err: at java.net.InetAddress.getAllByName(InetAddress.java:752)
08-10 19:26:58.275 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:188)
08-10 19:26:58.276 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.MysqlIO.(MysqlIO.java:301)
08-10 19:26:58.277 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188)
08-10 19:26:58.277 20891-20891/com.example.asaf.sql W/System.err: at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2221)

Here you have an example of a working method that connects to microsoft sql express
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
connection = DriverManager.getConnection("jdbc:jtds:sqlserver://replacewithip:port//DBNAME", "User", "Password"); // Connect to database
if (connection == null) {
ConnectionResult = "Verify connection";
Toast.makeText(activity, ConnectionResult, Toast.LENGTH_LONG).show();
} else {
//do something with your connection, in this case I executed a query
ResultSet rs = null;
String query = "EXEC AppMovil.INITE_Articulos_Familia '" + codigo + "'";
Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
//size = cantidad de rows, metodo para obtener cantidad de rows
rs = stmt.executeQuery(query);
ResultSetMetaData rsmtd = rs.getMetaData();
while(rs.next()){
ListaConsultaFamilia item = new ListaConsultaFamilia(
rs.getString("Codigo"),
rs.getString("Descripcion"),
rs.getString("Precio")
);
listaConsultaFamilias.add(item);
}
listaConsultaFamilias.size();
ConnectionResult = " successful";
isSuccess = true;
connection.close();
}
}catch (Exception ex)
{
//catch error while reading
Looper.prepare();
isSuccess = false;
Toast.makeText(activity, "No existen consultas en el periodo seleccionado", Toast.LENGTH_LONG).show();
ConnectionResult = ex.getMessage();
}

Related

Android app, http request to ip address fails

I have simple "gadget" based on Arduino. It is connected to the wlan of my house and sending web requests to it turns on/off a red LED indicating that I'm busy/free in my room. This works fine when called from a browser or from my small winforms application. It is called synchronous, it is just enough, no need for async calls.
But, I tried to create a android app that sends the same requests, no success. I have read many topics, tried different ways etc. The app has this row in manifest file:
android:networkSecurityConfig="#xml/network_security_config"
Maybe something is still missing. This might be very very basic, but I haven't been able to get it working. Code:
public void onViewCreated(#NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
binding.buttonFirst.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
OkHttpClient client = new OkHttpClient();
String url = "http://192.168.100.12/LED=ON";
Request req = new Request.Builder()
.url(url)
.build();
try {
client.newCall(req).execute();
} catch (IOException | RuntimeException e) {
e.printStackTrace();
}
NavHostFragment.findNavController(FirstFragment.this)
.navigate(R.id.action_FirstFragment_to_SecondFragment);
}
});
}
It fails on execute call. The app enters the catch section, but there's no understandable description in e. And of course, my mobile phone is connected to the same wlan.
Stack trace:
I/System.out: port:80
W/System.err: android.os.NetworkOnMainThreadException
W/System.err: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1513)
W/System.err: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:389)
W/System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
W/System.err: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
W/System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
W/System.err: at java.net.Socket.connect(Socket.java:631)
W/System.err: at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.kt:63)
W/System.err: at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:295)
W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
W/System.err: at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
W/System.err: at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
W/System.err: at com.example.donotdisturb.FirstFragment$1.onClick(FirstFragment.java:52)
W/System.err: at android.view.View.performClick(View.java:6603)
W/System.err: at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
W/System.err: at android.view.View.performClickInternal(View.java:6576)
W/System.err: at android.view.View.access$3100(View.java:780)
W/System.err: at android.view.View$PerformClick.run(View.java:26088)
W/System.err: at android.os.Handler.handleCallback(Handler.java:873)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err: at android.os.Looper.loop(Looper.java:193)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6705)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

java.lang.IllegalArgumentException while using GSON

I have this line of code
val event = Gson().fromJson(socketResponse.toString(), com.spaxiappuser.service.booking.event.Event::class.java)
Which throws the error
java.lang.IllegalArgumentException: class android.widget.TextView
declares multiple JSON fields named mMinWidth
My data class is as follows
data class Event(
val tripParams: TripParams? = null,
val onDemand: OnDemand? = null,
#SerializedName("request_id")
val requestId: String? = null,
#SerializedName("driver_userid")
val driverId: String? = null,
val due: Due? = null,
val standard: Standard? = null,
val isToAllowBackPress: Boolean = false
Can anyone please let me know why this is happening?
Here is my stack trace :
W/System.err: java.lang.IllegalArgumentException: class android.widget.TextView declares multiple JSON fields named mMinWidth
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:172)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.getAdapter(Gson.java:458)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:926)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:892)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:841)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:813)
W/System.err: at com.spaxiappuser.service.socket.EventManager.handleEvent(EventManager.kt:35)
W/System.err: at com.spaxiappuser.service.socket.Listener$listen$2.accept(Listener.kt:78)
W/System.err: at com.spaxiappuser.service.socket.Listener$listen$2.accept(Listener.kt:15)
W/System.err: at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onNext(ObservableDoOnEach.java:93)
W/System.err: at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeOnObserver.onNext(ObservableSubscribeOn.java:58)
W/System.err: at io.reactivex.internal.operators.observable.ObservableCreate$CreateEmitter.onNext(ObservableCreate.java:66)
W/System.err: at com.spaxiappuser.service.socket.Listener$listen$1.subscribe(Listener.kt:50)
W/System.err: at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)
W/System.err: at io.reactivex.Observable.subscribe(Observable.java:12197)
W/System.err: at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
W/System.err: at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
W/System.err: at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
W/System.err: at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err: at java.lang.Thread.run(Thread.java:919)
Any help in identifying the issue will be much appreciated.
One of the classes your model references has a TextView somewhere in it (or extends TextView), and GSON is trying to interpret that as a class to be inflated from JSON.
Find it and either mark that field transient, or otherwise exclude that field.

Permission denied error while Creating new File | Android

I am trying to create a image file to external storage to share it. but while trying following code I am having some error
var icon: Bitmap = BitmapFactory.decodeResource(resources, R.drawable.namelogo)
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.type = "image/*"
val bytes = ByteArrayOutputStream()
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes)
val path = File.separator + "temporary_file.jpg"
val f = File(Environment.getExternalStorageDirectory().toString(), path)
try {
if (!f.parentFile.exists())
f.parentFile.mkdirs()
if (!f.exists())
f.createNewFile()
f.createNewFile()
val fo = FileOutputStream(f)
fo.write(bytes.toByteArray())
} catch (e: IOException) {
Log.e("path = ", "+ $path " + e.toString())
e.printStackTrace()
}
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/IronyBalls/temporary_file.jpg"));
startActivity(Intent.createChooser(shareIntent, "Share Image"))
Till now I found solutions only to use
if (!f.parentFile.exists())
f.parentFile.mkdirs()
if (!f.exists())
f.createNewFile()
and
to set permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
that I have already used.But still gettig error as below
in Error Tab
E/path =: + /temporary_file.jpg java.io.IOException: Permission denied
and in info tab
W/System.err: java.io.IOException: Permission denied
W/System.err: at
java.io.UnixFileSystem.createFileExclusively0(Native Method)
W/System.err: at
java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:280)
W/System.err: at java.io.File.createNewFile(File.java:948)
W/System.err: at
com.irony.balls.MainActivity$onCreate$8.onClick(MainActivity.kt:277)
W/System.err: at android.view.View.performClick(View.java:5611)
10-15 20:33:17.912 29759-29759/com.irony.balls
W/System.err: at
android.view.View$PerformClick.run(View.java:22276) 10-15 20:33:17.912
29759-29759/com.irony.balls
W/System.err: at
android.os.Handler.handleCallback(Handler.java:751) 10-15 20:33:17.912
29759-29759/com.irony.balls
W/System.err: at
android.os.Handler.dispatchMessage(Handler.java:95) 10-15 20:33:17.912
29759-29759/com.irony.balls
W/System.err: at
android.os.Looper.loop(Looper.java:154) 10-15 20:33:17.912
29759-29759/com.irony.balls W/System.err: at
android.app.ActivityThread.main(ActivityThread.java:6195) 10-15
20:33:17.912 29759-29759/com.irony.balls W/System.err: at
java.lang.reflect.Method.invoke(Native Method) 10-15 20:33:17.912
29759-29759/com.irony.balls W/System.err: at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
10-15 20:33:17.912 29759-29759/com.irony.balls W/System.err: at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
If your device is working on Android 6 or higher have you already requested runtime permissions?
See https://developer.android.com/training/permissions/requesting.html for more details.

Android Twitter streaming api warning error on close

I am opening a twitter stream to get a constant stream of tweets, but when I attempt to close it I get the following system errors. The errors occur when the method stopStreaming() is called. I am using the Twitter twitter4j for streaming a statuses/filter.
public class FilterTweetsManager implements StatusListener//, Runnable
{
//
public void start(String[] keywords)
{
FilterQuery fq = new FilterQuery();
fq.track(keywords);
twitterStream_.addListener(this);
twitterStream_.filter(fq);
}
public void stopStreaming()
{
Handler handler = new Handler();
handler.post(new Runnable() {
#Override
public void run() {
twitterStream_.cleanUp(); // shutdown internal stream consuming thread
twitterStream_.shutdown(); // Shuts down internal dispatcher thread shared by all TwitterStream instances.
}
});
}
#Override
public void onStatus(twitter4j.Status status) {
Log.d(TAG, "onStatus " + status.getText());
}
//... rest of the StatusListener methods
}
The errors received are:
W/System.err: java.lang.IllegalStateException: Unbalanced enter/exit
W/System.err: at com.android.okhttp.okio.AsyncTimeout.enter(AsyncTimeout.java:62)
W/System.err: at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:209)
W/System.err: at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:306)
W/System.err: at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:300)
W/System.err: at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
W/System.err: at com.android.okhttp.internal.http.Http1xStream$ChunkedSource.readChunkSize(Http1xStream.java:451)
W/System.err: at com.android.okhttp.internal.http.Http1xStream$ChunkedSource.read(Http1xStream.java:435)
W/System.err: at com.android.okhttp.internal.Util.skipAll(Util.java:159)
W/System.err: at com.android.okhttp.internal.Util.discard(Util.java:141)
W/System.err: at com.android.okhttp.internal.http.Http1xStream$ChunkedSource.close(Http1xStream.java:472)
W/System.err: at com.android.okhttp.okio.RealBufferedSource.close(RealBufferedSource.java:396)
W/System.err: at com.android.okhttp.okio.RealBufferedSource$1.close(RealBufferedSource.java:384)
W/System.err: at java.util.zip.InflaterInputStream.close(InflaterInputStream.java:239)
W/System.err: at java.util.zip.GZIPInputStream.close(GZIPInputStream.java:137)
W/System.err: at twitter4j.StatusStreamBase.close(StatusStreamBase.java:335)
W/System.err: at twitter4j.TwitterStreamImpl$TwitterStreamConsumer.close(TwitterStreamImpl.java:685)
W/System.err: at twitter4j.TwitterStreamImpl.cleanUp(TwitterStreamImpl.java:386)
W/System.err: at cat.jorda.tweetfilter.FilterTweetsManager$1.run(FilterTweetsManager.java:63)
W/System.err: at android.os.Handler.handleCallback(Handler.java:789)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98)
W/System.err: at android.os.Looper.loop(Looper.java:164)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6541)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
W/TwitterStreamImpl: Unbalanced enter/exit
W/TwitterStreamImpl: Inflater has been closed

Uploading mp4 video to server, SSLException

I got SSLException while uploading video to the server via okhttp3.
final OkHttpClient clientOk = new OkHttpClient();
MultipartBody requestBody = new MultipartBody.Builder()
.addFormDataPart("file1", "file",
RequestBody.create(MediaType.parse("video/mp4"), sourceFile))
.addFormDataPart("id", id)
.build();
Request request = new Request.Builder()
.header("x_token", token)
.url(configuration.getApiBaseURLString() + "/path")
.post(requestBody)
.build();
clientOk.newCall(request).enqueue(new Callback() {
#Override
public void onFailure(Call call, IOException e) {
Log.d(TAG, "onFailure " + e.getMessage());
}
#Override
public void onResponse(Call call, Response response) throws IOException {
Log.d(TAG, "onResponse " + response.toString());
}
});
and error is
W/System.err: javax.net.ssl.SSLException: Write error: ssl=0x98e37a40: I/O error during system call, Broken pipe
W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:771)
W/System.err: at okio.Okio$1.write(Okio.java:80)
W/System.err: at okio.AsyncTimeout$1.write(AsyncTimeout.java:155)
W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
W/System.err: at okio.RealBufferedSink.write(RealBufferedSink.java:46)
W/System.err: at okhttp3.internal.http.Http1xStream$FixedLengthSink.write(Http1xStream.java:286)
W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
W/System.err: at okio.RealBufferedSink.writeAll(RealBufferedSink.java:104)
W/System.err: at okhttp3.RequestBody$3.writeTo(RequestBody.java:118)
W/System.err: at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.java:171)
W/System.err: at okhttp3.MultipartBody.writeTo(MultipartBody.java:113)
W/System.err: at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:704)
W/System.err: at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:563)
W/System.err: at okhttp3.RealCall.getResponse(RealCall.java:241)
W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
W/System.err: at okhttp3.RealCall.access$100(RealCall.java:30)
W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err: at java.lang.Thread.run(Thread.java:818)
Video size is 15.5 MB. Any thought what I'm doing wrong ?
Thank you in advance!
I am able to send sizes below 5MB. And on the backend I was told that set limit 'client_max_body_size' == 60MB

Categories

Resources