android-library
android-library copied to clipboard
invoked 'android.accounts.Account com.owncloud.android.lib.common.OwnCloudAccount.getSavedAccount()' on a null object reference
I thought i just have used the Sample code, but it seems that there are some issues...
Because i'm trying to get some ics files from the server i needed some webdav client but sardine-android
isn't working... "Only WebDAV Client allowed" ;/
So i tried that lib included as
com.github.owncloud:android-library:oc-android-library-0.9.24
The used Code:
Uri serverUri = Uri.parse("https://SOMESERVER.TLD/owncloud/");
OwnCloudClient mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, context, true);
OwnCloudCredentials creds = OwnCloudCredentialsFactory.newBasicCredentials("USERNAME","PASSWORD");
mClient.setCredentials(creds);
try {
ReadRemoteFolderOperation readFolder = new ReadRemoteFolderOperation("/");
RemoteOperationResult<ArrayList<RemoteFile>> readResponse = readFolder.execute(mClient);
Log.d("WEBDav",readResponse.getLogMessage());
if(readResponse.getData() != null)
for(RemoteFile file : readResponse.getData()){
Log.d("RemoteFile",file.getRemotePath());
}
...
Heyo here is my Log:
Synchronized /: Unexpected exception
java.lang.NullPointerException: Attempt to invoke virtual method 'android.accounts.Account com.owncloud.android.lib.common.OwnCloudAccount.getSavedAccount()' on a null object reference
at com.owncloud.android.lib.common.OwnCloudClient.getUserFilesWebDavUri(OwnCloudClient.java:263)
at com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation.run(ReadRemoteFolderOperation.java:79)
at com.owncloud.android.lib.common.operations.RemoteOperation.runOperation(RemoteOperation.java:252)
at com.owncloud.android.lib.common.operations.RemoteOperation.execute(RemoteOperation.java:215)
Hi @cs8898 , as you can see in your Log, you can not use the remote operations with no account, so using OwnCloudClientFactory.createOwnCloudClient
is not enough. I would recommend you to use something like:
Account account = new Account("name", "type")
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context);
By using this, you will obtain an OwnCloudClient with a proper account and it should work.
Thanks I will try that some day, currently i moved to Sardine-Android... They also support direct InputStreams what is pretty great in my case.
@davigonz I have the same problem, and I don't understand your solution. I already have a working owncloud account. So I just updated the values for: server_base_url, username, password - with the exact values I use in the browser. So the sample should work with that, right? I also tried with https://demo.owncloud.com/, demo, demo. Also not working.
In the sample app, the client is set with:
OwnCloudClient createOwnCloudClient(Uri uri, Context context, boolean followRedirects)
How can this work? getSavedAccount()
can only be null, cause it was never set, right? See the constructor:
public OwnCloudAccount(Uri baseUri, OwnCloudCredentials credentials) {
if (baseUri == null) {
throw new IllegalArgumentException("Parameter 'baseUri' cannot be null");
}
mSavedAccount = null;
mSavedAccountName = null;
mBaseUri = baseUri;
mCredentials = credentials != null ?
credentials : OwnCloudCredentialsFactory.getAnonymousCredentials();
String username = mCredentials.getUsername();
if (username != null) {
mSavedAccountName = AccountUtils.buildAccountName(mBaseUri, username);
}
}
mSavedAccountName is set, but mSavedAccount never.
And in your solution, where would the client get my credentials from?
Hello ! I have the same problem with the getSavedAccount(). Any solutions ?
How can this work? getSavedAccount() can only be null, cause it was never set, right? See the constructor:
@DanielKedl the error reported in the first comment is not about getting a null account when calling getSavedAccount() but trying to call getSavedAccount() from a null account, is not the same. Have a look at the logs:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.accounts.Account com.owncloud.android.lib.common.OwnCloudAccount.getSavedAccount()' on a null object reference
at com.owncloud.android.lib.common.OwnCloudClient.getUserFilesWebDavUri(OwnCloudClient.java:263)
And this occurs when you try to perform a network operation with a client without an account, as I explained in https://github.com/owncloud/android-library/issues/239#issuecomment-466339456
And in your solution, where would the client get my credentials from?
It would get your credentials from the account you use
https://github.com/owncloud/android-library/blob/24111a95d52204f81b61b178213dc5118b2015a3/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java#L78
But for that you might need to use a different constructor and create the credentials yourself.
https://github.com/owncloud/android-library/blob/24111a95d52204f81b61b178213dc5118b2015a3/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java#L91
Hi, same issue here.
This is how I setup ownCloudClient
val ownCloudClient = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(baseUrl), appContext, true)
ownCloudClient.credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password)
Above code works with this version: oc-android-library-0.9.15
but it doesn't work with 1.0.3
:
2019-11-28 17:45:24.074 23808-23930/ch.arcade.cloudcam.new E/ReadRemoteFolderOperation: Synchronized /: Unexpected exception
java.lang.NullPointerException: Attempt to invoke virtual method 'android.accounts.Account com.owncloud.android.lib.common.OwnCloudAccount.getSavedAccount()' on a null object reference
at com.owncloud.android.lib.common.OwnCloudClient.getUserFilesWebDavUri(OwnCloudClient.java:254)
at com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation.run(ReadRemoteFolderOperation.java:78)
at com.owncloud.android.lib.common.operations.RemoteOperation.runOperation(RemoteOperation.java:251)
at com.owncloud.android.lib.common.operations.RemoteOperation.run(RemoteOperation.java:270)