I want to check my MySQL database every second and get the data from it
This is what I tried I made the connection in a separate thread and make it sleep
Thread:
class Updater extends Thread {
ArrayList<chatData> list = new ArrayList<chatData>();
Boolean thereIsNewData = false;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String yourID = prefs.getString("KEY_USERNAME", "No login info available");
void getData(){
chatServiceHandler jsonParser = new chatServiceHandler();
ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
nvp.add(new BasicNameValuePair("yourID", yourID));
String json = jsonParser.makeServiceCall("http://example.com/getMSG.php", contactsServiceHandler.GET, nvp);
Log.d("Response: ", "> " + json);
if (json != null) {
try {
JSONObject jsonObj = new JSONObject(json);
if (jsonObj != null) {
list.clear();
JSONArray contactsArray = jsonObj.getJSONArray("MSGhandling");
for (int i = 0; i < contactsArray.length(); i++) {
JSONObject catObj = (JSONObject) contactsArray.get(i);
chatData cat = new chatData(catObj.getString("sender"), catObj.getString("receiver"),catObj.getString("msg"),catObj.getString("msgID"));
list.add(cat);
thereIsNewData = true;
}
}
} catch (JSONException e) {
e.printStackTrace();
thereIsNewData = false;
}
} else {
Log.e("JSON Data", "Didn't receive any data from server!");
thereIsNewData = false;
}
}
#Override
public void run() {
while (true) {
try {
DatabaseAdapter helper = new DatabaseAdapter(UpdaterService.this);
getData();
if(thereIsNewData){
for(int i =0; i < list.size(); i++){
chatData messages = list.get(i);
Log.d(TAG, "From: "+messages.getSenderID()+" TO:"+messages.getReceiverID()+" MSG: "+messages.getMSG());
helper.storeMSG(messages.getSenderID() , messages.getReceiverID() , messages.getMSG() , messages.getMsgID());
Intent newMessage = new Intent();
newMessage.setAction("NEW_MESSAGE");
sendBroadcast(newMessage);
}
list.clear();
thereIsNewData = false;
}else{
Log.d(TAG, "There is no new data");
}
sleep(1000);
} catch (InterruptedException e) {
}
}
}
}
It does it work but stops after a few seconds for half a minute and shows an error than back to do the same thing again:
-----------------------------------EDIT--------------------------------
LOG_CAT:
`190-318/system_process E/ThrottleService﹕ problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory) 03
04-02 10:37:44.162 389-403/com.android.systemui E/JavaBinder﹕ *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
java.lang.RuntimeException: android.os.DeadObjectException
at android.os.Parcel.writeException(Parcel.java:1326)
at android.os.Binder.execTransact(Binder.java:370)
at dalvik.system.NativeStart.run(Native Method)
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.content.IIntentReceiver$Stub$Proxy.performReceive(IIntentReceiver.java:121) at android.app.ActivityThread$ApplicationThread.scheduleRegisteredReceiver(ActivityThread.java:771) at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:381)
at android.os.Binder.execTransact(Binder.java:367)
at dalvik.system.NativeStart.run(Native Method)
04-02 10:41:00.282 630-644/com.khaled.zg W/System.err﹕ org.apache.http.conn.HttpHostConnectException: Connection to http://example.com refused
04-02 10:41:00.292 630-644/com.khaled.zg W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
04-02 10:41:00.292 630-644/com.khaled.zg W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
04-02 10:41:00.292 630-644/com.khaled.zg W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
04-02 10:41:00.306 630-644/com.khaled.zg W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
04-02 10:41:00.306 630-644/com.khaled.zg W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
04-02 10:41:00.306 630-644/com.khaled.zg W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
04-02 10:41:00.306 630-644/com.khaled.zg W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
04-02 10:41:00.313 630-644/com.khaled.zg W/System.err﹕ at com.khaled.zg.contactsServiceHandler.makeServiceCall(contactsServiceHandler.java:79)
04-02 10:41:00.326 630-644/com.khaled.zg W/System.err﹕ at com.khaled.zg.UpdaterService$Updater.getContacts(UpdaterService.java:101)
04-02 10:41:00.326 630-644/com.khaled.zg W/System.err﹕ at com.khaled.zg.UpdaterService$Updater.run(UpdaterService.java:135)
04-02 10:41:00.333 630-644/com.khaled.zg W/System.err﹕ Caused by: java.net.ConnectException: failed to connect to /185.27.134.163 (port 80): connect failed: ETIMEDOUT (Connection timed out)
04-02 10:41:00.345 630-644/com.khaled.zg W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:114)
04-02 10:41:00.345 630-644/com.khaled.zg W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
04-02 10:41:00.345 630-644/com.khaled.zg W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
04-02 10:41:00.353 630-644/com.khaled.zg W/System.err﹕ at java.net.Socket.connect(Socket.java:842)
04-02 10:41:00.353 630-644/com.khaled.zg W/System.err﹕ at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
04-02 10:41:00.364 630-644/com.khaled.zg W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
04-02 10:41:00.364 630-644/com.khaled.zg W/System.err﹕ ... 9 more
04-02 10:41:00.364 630-644/com.khaled.zg W/System.err﹕ Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
04-02 10:41:00.383 630-644/com.khaled.zg W/System.err﹕ at libcore.io.Posix.connect(Native Method)
04-02 10:41:00.383 630-644/com.khaled.zg W/System.err﹕ at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
04-02 10:41:00.393 630-644/com.khaled.zg W/System.err﹕ at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
04-02 10:41:00.393 630-644/com.khaled.zg W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:112)`
Am I doing it wrong? is there any other way or a solution to my problem?
Or does the host is what causes the problem?
Related
I have my GameActivity that is a simple quiz. I set up two Runnables, mRunnableQuestion and mRunnableQuestionWithPenalty. The logic is: mRunnableQuestion shows new question and waits 30 seconds, when user doesn't answer in this time, the other Runnable is called, which gives user points penalty:
private Runnable mRunnableQuestion = new Runnable() {
#Override
public void run() {
new AsyncAPIGetQuestion().execute(mCategoryId);
mHandler.postDelayed(mRunnableQuestionWithPenalty, 30000);
}
};
Of course, when user answers in time, I give user points and restart the Runnable:
mHandler.removeCallbacksAndMessages(null);
mHandler.post(mRunnableQuestion);
It works very well. However, I wanted to color the Cards based on correct/wrong answer and wait 5 seconds. So i changed code above to:
mHandler.removeCallbacksAndMessages(null);
colorAnswers();
mHandler.postDelayed(mRunnableQuestion, 5000);
This is where the problem begins. When I run my app, after 2, 3 or 4 questions I get a EOF/BufferedInputStream error:
03-04 13:38:24.107 16506-16532/com.my.pkg W/System.err: java.io.EOFException
03-04 13:38:24.107 16506-16532/com.my.pkg W/System.err: at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:95)
03-04 13:38:24.107 16506-16532/com.my.pkg W/System.err: at com.
android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:175)
03-04 13:38:24.107 16506-16532/com.my.pkg W/System.err: at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101)
03-04 13:38:24.107 16506-16532/com.my.pkg W/System.err: at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:616)
03-04 13:38:24.107 16506-16532/com.my.pkg W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:379)
03-04 13:38:24.107 16506-16532/com.my.pkg W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323)
03-04 13:38:24.108 16506-16532/com.my.pkg W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:190)
03-04 13:38:24.108 16506-16532/com.my.pkg W/System.err: at com.my.pkg.JSONParser.getJSONFromUrl(JSONParser.java:45)
03-04 13:38:24.108 16506-16532/com.my.pkg W/System.err: at com.my.pkg.GameActivity$AsyncAPIGetQuestion.doInBackground(GameActivity.java:317)
03-04 13:38:24.108 16506-16532/com.my.pkg W/System.err: at com.my.pkg.GameActivity$AsyncAPIGetQuestion.doInBackground(GameActivity.java:299)
03-04 13:38:24.108 16506-16532/com.my.pkg W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-04 13:38:24.108 16506-16532/com.my.pkg W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-04 13:38:24.108 16506-16532/com.my.pkg W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-04 13:38:24.108 16506-16532/com.my.pkg W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-04 13:38:24.108 16506-16532/com.my.pkg W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-04 13:38:24.108 16506-16532/com.my.pkg W/System.err: at java.lang.Thread.run(Thread.java:818)
03-04 13:38:24.108 16506-16532/com.my.pkg E/JSONParser.java: Error converting result java.io.IOException: BufferedInputStream is closed
It ONLY happens, when I add the extra postDelayed() there. No problems before.
My doInBackground part of AsyncTask that is executed by Runnable and that returns an error as stated above
#Override
protected JSONArray doInBackground(String... params) {
JSONParser jParser = new JSONParser();
JSONArray json = jParser.getJSONFromUrl(apiURL);
return json;
}
And the JSONParser.getJSONFromURL:
public JSONArray getJSONFromUrl(String urlSource) {
try {
URL url = new URL(urlSource);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
inputStream = new BufferedInputStream(urlConnection.getInputStream());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
if(!reader.ready()) {
break;
}
}
inputStream.close();
json = sb.toString();
} catch (Exception e) {
Log.e(TAG, "Error converting result " + e.toString());
}
try {
jArr = new JSONArray(json);
} catch (JSONException e) {
Log.e(TAG, "Error parsing data " + e.toString());
}
return jArr;
}
I would really appreciate any help. All the best!
It looks like I solved this issue.
The problem was in my jParser.getJSONFromUrl() method, specifically these lines:
URL url = new URL(urlSource);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
It seems that you only set setDoOutput parameter as true, when you are using POST/PUT requests. If you want only perform a GET request, such as in my case, you should set it as false:
urlConnection.setDoOutput(false);
Otherwise, you can end up getting errors as described above.
Best regards to the Community!
I have developed an app in android to find power shut down.When i run the app ,unfortunately closed once I debug the app.Here I got the error in doInbackground
My java code is here
private static final String URL = "http://livechennai.com/powershutdown_news_chennai.asp";
//private static final String URL = "http://livechennai.com/powercut_schedule.asp";
ProgressDialog mProgressDialog;
EditText filterItems;
ArrayAdapter<String> arrayAdapter;
protected String[] doInBackground(Void... params) {
ArrayList<String> hrefs=new ArrayList<String>();
try {
// Connect to website
Document document = Jsoup.connect(URL).get();
// Get the html document title
websiteTitle = document.title();
Elements table=document.select("#table13>tbody>tr>td>a[title]");
for(Element link:table){
hrefs.add(link.attr("abs:href"));
//int arraySize=hrefs.size();
//websiteDescription=link.attr("abs:href");
}
} catch (IOException e) {
e.printStackTrace();
}
//get the array list values
for(String s:hrefs)
{
websiteDescription=hrefs.get(0);
websiteDescription1=hrefs.get(1);
websiteDescription2=hrefs.get(2);
websiteDescription3=hrefs.get(3);
}
Below is the error log
06-09 23:17:10.284 17923-17937/com.example.poweralert.app E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
Caused by: java.lang.IllegalArgumentException: Must supply a valid URL
at org.jsoup.helper.Validate.notEmpty(Validate.java:102)
at org.jsoup.helper.HttpConnection.url(HttpConnection.java:60)
at org.jsoup.helper.HttpConnection.connect(HttpConnection.java:30)
at org.jsoup.Jsoup.connect(Jsoup.java:73)
at com.example.poweralert.app.PrimaryActivity$FetchWebsiteData.doInBackground(PrimaryActivity.java:144)
at com.example.poweralert.app.PrimaryActivity$FetchWebsiteData.doInBackground(PrimaryActivity.java:100)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
06-09 23:17:10.
How to solve this error/issue? It shows null in website description .
Looks like there is an error in URL connection. Are you not passing valid URL?
Caused by: java.lang.IllegalArgumentException: Must supply a valid URL
Crash is: java.lang.RuntimeException: An error occured while executing doInBackground()
Why I am getting a crash on the HttpResponse response = client.execute(httpGet); line here? Does it have something to do with my ThreadPolicy?
From my fragment I call this:
new ReadJSONFeedMainTask().execute(urlString);
....
private class ReadJSONFeedMainTask extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
return Helper.readJSONFeed(urls[0]);
}
protected void onPostExecute(String result) {
// do stuff
}
}
}
Then it's called here:
public static String readJSONFeed(String URL) {
ThreadPolicy tp = ThreadPolicy.LAX;
StrictMode.setThreadPolicy(tp);
String numberValue = URL.replaceAll(" ", "%20");
StringBuilder stringBuilder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(numberValue);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
} else {
Log.e("JSON", "Failed to download file");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString();
}
Stacktrace:
java.lang.RuntimeException: An error occured while executing doInBackground()
1 at android.os.AsyncTask$3.done(AsyncTask.java:299)
2 at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
3 at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
4 at java.util.concurrent.FutureTask.run(FutureTask.java:239)
5 at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
6 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
7 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
8 at java.lang.Thread.run(Thread.java:856)
9Caused by: com.splunk.mint.network.util.DelegationException: java.net.ConnectException: failed to connect to 50-89-72-86.res.bhn.net/50.89.72.86 (port 80): connect failed: ETIMEDOUT (Connection timed out)
10 at com.splunk.mint.network.util.Delegator.invoke0(Delegator.java:62)
11 at com.splunk.mint.network.util.Delegator.invoke(Delegator.java:45)
12 at com.splunk.mint.network.socket.MonitoringSocketImpl.connect(MonitoringSocketImpl.java:118)
13 at java.net.Socket.connect(Socket.java:842)
14 at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
15 at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
16 at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
17 at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
18 at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
19 at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
20 at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
21 at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
22 at com.sortitapps.movies.Helper.readJSONFeed(Helper.java:1282)
23 at com.sortitapps.movies.MainFragment$ReadJSONFeedMainTask.doInBackground(MainFragment.java:680)
24 at com.sortitapps.movies.MainFragment$ReadJSONFeedMainTask.doInBackground(MainFragment.java:678)
25 at android.os.AsyncTask$2.call(AsyncTask.java:287)
26 at java.util.concurrent.FutureTask.run(FutureTask.java:234)
27 ... 4 more
28Caused by: java.net.ConnectException: failed to connect to 50-89-72-86.res.bhn.net/50.89.72.86 (port 80): connect failed: ETIMEDOUT (Connection timed out)
29 at libcore.io.IoBridge.connect(IoBridge.java:114)
30 at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
31 at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
32 at java.lang.reflect.Method.invokeNative(Native Method)
33 at java.lang.reflect.Method.invoke(Method.java:511)
34 at com.splunk.mint.network.util.Delegator.invoke0(Delegator.java:56)
35 ... 20 more
36Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
37 at libcore.io.Posix.connect(Native Method)
38 at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
39 at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
40 at libcore.io.IoBridge.connect(IoBridge.java:112)
I had the same problem after updating from BugSense to Splunk Mint and there was nothing wrong with my code. After I commented out Splunk.init(...) method invocation everything started to work again. Problem was occuring only on HTC devices and with Splunk Mint enabled - all calls of HttpClient#execute() method were throwing DelegationException. Not sure if this is your case but maybe my answer will help someone with the same problem as mine.
It seems pretty clear, the end of the stack trace indicates Connection timed out. Your server is unreachable.
You should use Asynctask for any work with server, see http://developer.android.com/reference/android/os/AsyncTask.html
My program should work as follows:
1.Copy the new database in the program folder
2.Import the records from the old database to the new one.
But I for some reason get an exception. Why?
protected Object doInBackground(Object[] objects) {
String LOCAL_DATABASE_PATH = getApplicationInfo().dataDir + File.separator +
"databases" + File.separator;
File fileDir = new File(LOCAL_DATABASE_PATH);
if (!fileDir.exists())
fileDir.mkdirs();
File tempFile = new File(LOCAL_DATABASE_PATH + DATABASE_NAME);
try {
tempFile.createNewFile(); // here I catch exception
InputStream is = SplashActivity.this.getAssets().open(
DATABASE_NAME);
FileOutputStream os = new FileOutputStream(new File(
LOCAL_DATABASE_PATH, DATABASE_NAME));
int bufferLength = 0;
byte[] buffer = new byte[2048];
while ((bufferLength = is.read(buffer)) > 0) {
os.write(buffer, 0, bufferLength);
}
Preferences.getInstance(SplashActivity.this).
set(Preferences.IS_DATABASE_COPYING_ON_DEVICE, true);
is.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
I am getting the following error
java.io.IOException: open failed: EACCES (Permission denied)
08-28 09:32:27.977 32558-32558/com.DriverNotes.AndroidMobileClientTest D/libEGL﹕ loaded /system/lib/egl/libGLES_hawaii.so
08-28 09:32:27.977 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at java.io.File.createNewFile(File.java:948)
08-28 09:32:27.977 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at com.DriverNotes.AndroidMobileClientTest.SplashActivity$DataBaseLoadTask.doInBackground(SplashActivity.java:73)
08-28 09:32:27.977 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-28 09:32:27.977 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-28 09:32:27.977 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
08-28 09:32:27.977 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-28 09:32:27.977 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-28 09:32:27.977 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at java.lang.Thread.run(Thread.java:856)
08-28 09:32:27.987 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
08-28 09:32:27.987 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at libcore.io.Posix.open(Native Method)
08-28 09:32:27.987 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
08-28 09:32:27.987 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ at java.io.File.createNewFile(File.java:941)
08-28 09:32:27.987 32558-32587/com.DriverNotes.AndroidMobileClientTest W/System.err﹕ ... 7 more
When creating the tempFile try using the fileDir you already created to get sure it exists.
File tempFile = new File(fileDir, DATABASE_NAME);
Before you create a new file you should check if it already exists by calling its exits() method. And then instead of opening it again you should actually keep on using it. Or at least close it before opening again.
if(!tempFile.exists())
tempFile.createNewFile();
InputStream is = SplashActivity.this.getAssets().open(
DATABASE_NAME);
FileOutputStream os = new FileOutputStream(tempFile);
Create you FileOutPutStream using the tempFile or close tempFile to get sure your file is not locked.
This question already has answers here:
Error message 'java.net.SocketException: socket failed: EACCES (Permission denied)'
(10 answers)
Closed 8 years ago.
I'm trying to use Telegram Java API https://github.com/ardock/telegram-api
and I started with some simple RPC call:
SampleApiState apiState = new SampleApiState(connections);
TLRequestAuthCheckPhone checkRequest = new TLRequestAuthCheckPhone("+1234567890");
TelegramApi api = new TelegramApi(apiState, new ApplicationInfo(),
new ApiCallback() {
#Override
public void onUpdatesInvalidated(TelegramApi api) {
// TODO Auto-generated method stub
Log.i(TAG, "onUpdatesInvalidated");
}
#Override
public void onAuthCancelled(TelegramApi api) {
// TODO Auto-generated method stub
Log.i(TAG, "onAuthCancelled");
}
#Override
public void onUpdate(TLAbsUpdates updates) {
// TODO Auto-generated method stub
Log.i(TAG, "onUpdate");
}
});
TLCheckedPhone checkedPhone = api.doRpcCall(checkRequest);
And here is log:
11524-11580/com.example.tltest W/System.err﹕ java.net.SocketException: socket failed: EACCES (Permission denied)
11524-11580/com.example.tltest W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:576)
11524-11580/com.example.tltest W/System.err﹕ at java.net.PlainSocketImpl.create(PlainSocketImpl.java:201)
11524-11580/com.example.tltest W/System.err﹕ at java.net.Socket.checkOpenAndCreate(Socket.java:664)
11524-11580/com.example.tltest W/System.err﹕ at java.net.Socket.connect(Socket.java:808)
11524-11580/com.example.tltest W/System.err﹕ at org.telegram.mtproto.transport.PlainTcpConnection.<init>(PlainTcpConnection.java:32)
11524-11580/com.example.tltest W/System.err﹕ at org.telegram.mtproto.pq.Authorizer.doAuth(Authorizer.java:198)
11524-11580/com.example.tltest W/System.err﹕ at org.telegram.api.engine.TelegramApi$ConnectionThread.waitForDc(TelegramApi.java:842)
11524-11580/com.example.tltest W/System.err﹕ at org.telegram.api.engine.TelegramApi$ConnectionThread.run(TelegramApi.java:907)
11524-11588/com.example.tltest I/System.out﹕ api#1001#Uploader:UploadFileThread iteration
11524-11580/com.example.tltest W/System.err﹕ Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)
11524-11580/com.example.tltest W/System.err﹕ at libcore.io.Posix.socket(Native Method)
11524-11580/com.example.tltest W/System.err﹕ at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)
11524-11580/com.example.tltest W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:561)
11524-11580/com.example.tltest W/System.err﹕ ... 7 more
11524-11580/com.example.tltest I/System.out﹕ TransportRate:onConnectionFailure #1
11524-11580/com.example.tltest I/System.out﹕ TransportRate:Transport: #1 173.240.5.1:443 #1.0
11524-11580/com.example.tltest I/System.out﹕ TransportRate:tryConnection #1
After connection failure, it tries to connect again and again, but not very successfully. I couldn't find out what's the reason and how to solve this problem. Maybe someone had same problem? Will be very gratefull for some help)
From the exception you posted it seems it is an android app and this is a permission problem.
java.net.SocketException: socket failed: EACCES (Permission denied)
Try to add this to the manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />