0

I created an application to call an alarm manager to repeat the task every 1 hours, when the alarm manager is trigger, and I have other function to onReceive the alarm manager.

public void onReceive(Context context, Intent intent) {
    loadClassFromAsp();

    if (MainActivity.gCountBook >= 1) {
        MyNotificationScheduler.showNotification(context, Access.class, "Class Reminder !!", "Don't miss your class on next hour !!");
    }
}

public void loadClassFromAsp() {
    String Url;

    Uri.Builder builder = new Uri.Builder();
    builder.scheme("")
            .authority("192.168.0.28")
            .appendPath("sfitness")
            .appendPath("apps")
            .appendPath("checkBooking.asp");

    Url = builder.build().toString();

    MyNotificationReceiver.getBook task = new MyNotificationReceiver.getBook();
    task.execute(Url);

}

On the uri builder I have a AsynTask function also

private class getBook extends AsyncTask<String, Void, Void> {

    private String responseString = null;
    //private ProgressDialog dialog = new ProgressDialog(getContext());

    protected void onPreExecute() {

    }

    protected Void doInBackground(String... urls) {
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(Url);
        //From this place onwards, my program end and pop error
        try {
            HttpResponse response = client.execute(request);
            InputStream in = response.getEntity().getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            StringBuilder str = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                str.append(line);
            }
            responseString = str.toString();
        } catch (ClientProtocolException e) {
            responseString = "Error! Client Protocol Exception";
        } catch (IOException e) {
            responseString = "Please Login Check your Internet connection."; //No Internet Access!
        }
        return null;
    }

    protected void onPostExecute(Void unused) {

        if (responseString != null) {
            String sGetString = responseString.substring(0, responseString.indexOf("|"));
            String sGet = responseString.toString();
            MainActivity.gCountBook = Integer.parseInt(sGetString);
            List classBook = new ArrayList<String>();

            for (int i = 0; i < MainActivity.gCountBook; i++) {
                sGet = sGet.substring(sGet.indexOf("|") + 1, sGet.length());
                String data = sGet.substring(0, sGet.indexOf("|"));
            }
        }
    }
}

On my AsynTask function, after the HttpGet and enter into try, my application pop out and said "Unfortunately, your apps has stopped" This is what I get from debugger. There is no error, nothings. Every time my apps run until the try statement automatically pop out. Anyone know the solution for this ? I have no idea why.

I have similar function that done in other class, that function run flawless I have no idea what is the problem inside. I added receiver in my manifest too.

Thanks, if anything you need me to update please do tell me. Thanks !!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 3
    *There is no error, nothings* - Did you check the logcat? – BackSlash Jun 07 '18 at 08:15
  • It might be something to do with how you are accessing things across threads. – IAmGroot Jun 07 '18 at 08:17
  • @Ben the Url is come from the builder, I check my debugger, the Url did get a value so is not error from there. –  Jun 07 '18 at 08:18
  • apps don't just stop for no reason. There will be an error somewhere. Check if you're not filtering the logcat or have the wrong device selected – Tim Jun 07 '18 at 08:19
  • I have check my logcat, it shows nothings. I know apps won't stop for no reason, just that I don't know where is the reason. And I selected the right device. –  Jun 07 '18 at 08:21
  • check how to debug here https://developer.android.com/studio/debug/ , check *View the system log* section – Navneet Krishna Jun 07 '18 at 08:24
  • And there's nothing in the logcat that starts with `E/` or contains the phrase `caused by`? – Michael Dodd Jun 07 '18 at 09:08
  • No, there is nothing when the try method is trigger, my application closed and a error message pop up and said "Unfortunately myApplication has stopped" that's it. –  Jun 07 '18 at 09:16

0 Answers0