23tony
Well-Known Member
I'm facing a bit of a quandry: I'm implementing an interface that isn't cooperating.
Background: this is for a basic HTTP connection to download JSON data. I used the guide at https://developer.android.com/training/basics/network-ops/connecting and implemented pretty much exactly what is there. I'm now trying to implement the interface in another activity, but it seems to not be recognizing one of the functions.
Interface is DownloadCallback:
And the activity:
(I left off the imports. Package declarations were created automatically by Android Studio and have been verified to be the same)
With this code, I'm getting the warning: Class 'DummyActivity' must either be declared abstract or implement abstract method 'updateFromDownload(T)' from 'DownloadCallback' on the class declaration, and Method does not override method from its superclass on the @override declaration.
I've tried declaring the method private, protected, public, or even leaving that off completely, with no success. I've copied/pasted the function name from the interface just to be sure I wasn't misspelling without noticing. No matter what I do I can't get it to recognize that I'm overriding it.
I'm relatively new to Java and really new to Android so I'm sure I'm missing something pretty obvious, but I can't see what it is. Anyone have any ideas?
Background: this is for a basic HTTP connection to download JSON data. I used the guide at https://developer.android.com/training/basics/network-ops/connecting and implemented pretty much exactly what is there. I'm now trying to implement the interface in another activity, but it seems to not be recognizing one of the functions.
Interface is DownloadCallback:
Code:
public interface DownloadCallback<T> {
interface Progress {
int ERROR = -1;
int CONNECT_SUCCESS = 0;
int GET_INPUT_STREAM_SUCCESS = 1;
int PROCESS_INPUT_STREAM_IN_PROGRESS = 2;
int PROCESS_INPUT_STREAM_SUCCESS = 3;
}
/**
* Call from main thread to update the UI
* @param result
*/
void updateFromDownload(T result);
/**
* Get the device's active network status as a NetworkInfo object
* @return
*/
NetworkInfo getActiveNetworkInfo();
/**
* Show progress update
* @param progressCode one of the constants defined above
* @param percentComplete 0-100
*/
void onProgressUpdate(int progressCode, int percentComplete);
/**
* Called when process has finished regardless of success of download.
*/
void finishDownloading();
}
And the activity:
Code:
public class DummyActivity extends AppCompatActivity implements DownloadCallback {
private NetworkFragment networkFragment;
private boolean downloading = false;
private TextView mTextView2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dummy);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
mTextView2 = findViewById(R.id.textView2);
networkFragment = NetworkFragment.getInstance(getSupportFragmentManager(), getString(R.string.base_url));
}
@Override
private void updateFromDownload(String result) {
mTextView2.setText(result);
}
private void startDownload() {
if (!downloading && networkFragment != null) {
networkFragment.startDownload();
downloading = true;
}
}
}
With this code, I'm getting the warning: Class 'DummyActivity' must either be declared abstract or implement abstract method 'updateFromDownload(T)' from 'DownloadCallback' on the class declaration, and Method does not override method from its superclass on the @override declaration.
I've tried declaring the method private, protected, public, or even leaving that off completely, with no success. I've copied/pasted the function name from the interface just to be sure I wasn't misspelling without noticing. No matter what I do I can't get it to recognize that I'm overriding it.
I'm relatively new to Java and really new to Android so I'm sure I'm missing something pretty obvious, but I can't see what it is. Anyone have any ideas?