Evernote getNoteContent() 异步任务错误
Evernote getNoteContent() Asynctask Error
我正在使用 Evernote 的 SDK 为 Android 做一个项目。我试图从我的一个笔记(onItemClick)中获取内容,但每次我使用该方法时,应用程序都会因线程异常而崩溃。
这是我使用方法的代码部分:
public void onFragmentInteraction(Note note) throws EDAMUserException, EDAMSystemException, EDAMNotFoundException, TException, ExecutionException, InterruptedException {
String noteGuid = note.getGuid();
String Content = new GetNoteTask().execute(noteGuid).get();
Intent intent = new Intent(this, ViewNoteActivity.class);
intent.putExtra(intent.EXTRA_TEXT, Content);
startActivity(intent);
}
public class GetNoteTask extends AsyncTask<String, Void, String> {
private EvernoteSession mEvernoteSession;
public String noteContent(String guid) throws EDAMUserException, EDAMSystemException, TException, EDAMNotFoundException {
final EvernoteNoteStoreClient noteStoreClient = mEvernoteSession.getEvernoteClientFactory().getNoteStoreClient();
String noteText;
noteText = noteStoreClient.getNoteContent(guid);
return noteText;
}
@Override
protected String doInBackground(String... params) {
String guid = params[0];
String noteContent = null;
try {
noteContent = noteContent(guid);
} catch (EDAMUserException e) {
e.printStackTrace();
} catch (EDAMSystemException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
} catch (EDAMNotFoundException e) {
e.printStackTrace();
}
return noteContent;
}
}
第一个方法位于我的 MainActivity 中,它扩展了一个 Fragment。第二个是我获取内容注释的任务。当我在 asynctask 中初始化 Evernote 客户端时,它中断了。
final EvernoteNoteStoreClient noteStoreClient = mEvernoteSession.getEvernoteClientFactory().getNoteStoreClient();
String noteText;
我已经找到解决办法了。如果没有在我的 Main Activity 中声明的已使用的 mEvernoteSession,我无法调用 EvernoteClient,因此我尝试发送 noteStoreClient 但它始终为空,因为该方法是私有的且不受保护,所以我没有填写当我发送它时。
最后我创建了一个 Static class 来保存我的变量:
public static class MyTaskParams{
public String guid;
public EvernoteNoteStoreClient noteStore;
public MyTaskParams(String noteGuid, EvernoteNoteStoreClient noteStoreClient) {
this.guid=noteGuid;
this.noteStore=noteStoreClient;
}
我稍后将其发送到 AsyncTask。
MyTaskParams params = new MyTaskParams(noteGuid,noteStoreClient);
GetNoteTask GetNoteTask = new GetNoteTask();
最后我的 Asynctask 看起来像:
public class GetNoteTask extends AsyncTask<MainActivity.MyTaskParams,Void , String> {
public String noteContent(EvernoteNoteStoreClient noteStoreClient, String guid) throws EDAMUserException, EDAMSystemException, TException, EDAMNotFoundException {
String noteText;
noteText = noteStoreClient.getNoteContent(guid);
return noteText;
}
protected String doInBackground(MainActivity.MyTaskParams... params) {
String noteContent = null;
String guid = params[0].guid;
EvernoteNoteStoreClient noteStoreClient = params[0].noteStore;
try {
noteContent = noteContent(noteStoreClient, guid);
} catch (EDAMUserException e) {
e.printStackTrace();
} catch (EDAMSystemException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
} catch (EDAMNotFoundException e) {
e.printStackTrace();
}
return noteContent;
}
我正在使用 Evernote 的 SDK 为 Android 做一个项目。我试图从我的一个笔记(onItemClick)中获取内容,但每次我使用该方法时,应用程序都会因线程异常而崩溃。 这是我使用方法的代码部分:
public void onFragmentInteraction(Note note) throws EDAMUserException, EDAMSystemException, EDAMNotFoundException, TException, ExecutionException, InterruptedException {
String noteGuid = note.getGuid();
String Content = new GetNoteTask().execute(noteGuid).get();
Intent intent = new Intent(this, ViewNoteActivity.class);
intent.putExtra(intent.EXTRA_TEXT, Content);
startActivity(intent);
}
public class GetNoteTask extends AsyncTask<String, Void, String> {
private EvernoteSession mEvernoteSession;
public String noteContent(String guid) throws EDAMUserException, EDAMSystemException, TException, EDAMNotFoundException {
final EvernoteNoteStoreClient noteStoreClient = mEvernoteSession.getEvernoteClientFactory().getNoteStoreClient();
String noteText;
noteText = noteStoreClient.getNoteContent(guid);
return noteText;
}
@Override
protected String doInBackground(String... params) {
String guid = params[0];
String noteContent = null;
try {
noteContent = noteContent(guid);
} catch (EDAMUserException e) {
e.printStackTrace();
} catch (EDAMSystemException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
} catch (EDAMNotFoundException e) {
e.printStackTrace();
}
return noteContent;
}
}
第一个方法位于我的 MainActivity 中,它扩展了一个 Fragment。第二个是我获取内容注释的任务。当我在 asynctask 中初始化 Evernote 客户端时,它中断了。
final EvernoteNoteStoreClient noteStoreClient = mEvernoteSession.getEvernoteClientFactory().getNoteStoreClient();
String noteText;
我已经找到解决办法了。如果没有在我的 Main Activity 中声明的已使用的 mEvernoteSession,我无法调用 EvernoteClient,因此我尝试发送 noteStoreClient 但它始终为空,因为该方法是私有的且不受保护,所以我没有填写当我发送它时。
最后我创建了一个 Static class 来保存我的变量:
public static class MyTaskParams{
public String guid;
public EvernoteNoteStoreClient noteStore;
public MyTaskParams(String noteGuid, EvernoteNoteStoreClient noteStoreClient) {
this.guid=noteGuid;
this.noteStore=noteStoreClient;
}
我稍后将其发送到 AsyncTask。
MyTaskParams params = new MyTaskParams(noteGuid,noteStoreClient);
GetNoteTask GetNoteTask = new GetNoteTask();
最后我的 Asynctask 看起来像:
public class GetNoteTask extends AsyncTask<MainActivity.MyTaskParams,Void , String> {
public String noteContent(EvernoteNoteStoreClient noteStoreClient, String guid) throws EDAMUserException, EDAMSystemException, TException, EDAMNotFoundException {
String noteText;
noteText = noteStoreClient.getNoteContent(guid);
return noteText;
}
protected String doInBackground(MainActivity.MyTaskParams... params) {
String noteContent = null;
String guid = params[0].guid;
EvernoteNoteStoreClient noteStoreClient = params[0].noteStore;
try {
noteContent = noteContent(noteStoreClient, guid);
} catch (EDAMUserException e) {
e.printStackTrace();
} catch (EDAMSystemException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
} catch (EDAMNotFoundException e) {
e.printStackTrace();
}
return noteContent;
}