0

I am trying to leverage the solution shown here, How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class?, and noticed that while the code compiles and is running fine, Android Studio is indicating it is in error and underlining it. New to Android so I would welcome a pointer in the right direction.

Specifically I have this code written:

public class HttpRequest extends AsyncTask <HttpRequestParam, Void, String> {
    public AsyncResponse delegate = null;


    public HttpRequest(AsyncResponse delegate){
        this.delegate = delegate;
    }

    @Override
    protected String doInBackground(HttpRequestParam... hr) { // }
...
}

It all compiles and works great, but Android studio is complaining:

"Cannot access com.foo.bar.HttpRequestParam"

The same complaint surfaces in the routine in MainActivity.java where I invoke the HttpRequest:

        new HttpRequest(new AsyncResponse() {
            @Override
            public void processFinish(String output) {
                Log.v(TAG, "registerUser async callback completed");
                linearThemepackProgress.setVisibility(View.GONE);
            }
        }).execute(hr);

HttpRequestParam is a simple class I am using to marshal the specific attributes I need to set on the connection and is part of the package (hence it compiles in spite of generating three errors).

Pointers would be welcome.

I must be missing something and am worried that I am overlooking something that could be fragile. I would welcome any pointers...

UPDATE: the same error indicator appears across the entirety of the invocations from my MainActivity where all the lines below are tagged with an error indicator underline!

        HttpRequestParam hr = new HttpRequestParam(mContext, this.userRegistrationString(), null, "POST");
        linearThemepackProgress.setVisibility(View.VISIBLE);
        Log.v(TAG, "ClientUserRequest: " + hr);
        new HttpRequest(new AsyncResponse() {
            @Override
            public void processFinish(String output) {
                Log.v(TAG, "registerUser async callback completed");
                linearThemepackProgress.setVisibility(View.GONE);
            }
        }).execute(hr);

The HttpParamRequest class shown below:

public class HttpRequestParam {
  private String mUrl;        // The URL to be connected to
  private File mFile;         // The directory for the temporary file
  private String mHttpType;   // Whether the HTTP connection is for posting or download
  private Context mContext;   // User context
  HttpRequestParam(Context c, String s, File f, String ht) {
    mUrl = s;
    mFile = f;
    mHttpType = ht;
    mContext = c;
  }
  File getFile() {
    return mFile;
  }
  String getUrl() {
    return mUrl;
  }
  String getType() {
    return mHttpType;
  }
  Context getContext() {
    return mContext;
  }
}
  • your constructor method does not call super, so your new class no correct init – Lenoarod Oct 10 '19 at 05:09
  • Can you add the HttpRequestParam Class and all of the errors? You can try to "stand" on the underlined code and hit `Alt + Enter`. it will bring you suggestions on how to fix this issue. – Yoav Gibri Oct 10 '19 at 06:04
  • Lenoarod - I added a call to super() in the basic constructor but the underline error remains. I did notice that if I comment out the constructor entirely, the error indication does not go away (but then the functionality is broken). – HapkidoNinja Oct 10 '19 at 23:12
  • Yoav - Thanks, I updated the above to include that class but it really is barebones for now. I suspect the class definition is not the issue but it is something more intrinsic to the AsyncTask interplay or Android Studio. The same error indicator appears on the class definition of HttpRequest and on the invocations from my MainActivity (I added that in as well). Alt+Enter was not helpful and none of the suggestions affect the error. – HapkidoNinja Oct 10 '19 at 23:34

2 Answers2

0

Good day. Why don't you use the retrofit library instead of writing this async task? I prefer you to go with the retrofit library, It will handle all the Http request for you in a simple and secure way.

Please look at this Retrofit

Retrofit with SOAP

Nick
  • 195
  • 1
  • 5
  • Thanks Nick. The simple answer is that I was unaware of this library. At this point I want to try and understand what the core issue here is, since AStudio continues to indicate an error, but the project compiles and executes correctly. – HapkidoNinja Oct 10 '19 at 23:36
0

After several hours of playing around without a clear clue I tried to:

  1. delete the HttpParam class file
  2. clean the project
  3. recreate the file working through the Android Studio interface for class declaration
  4. rerun code analysis

The problem seems to have resolved itself.