我正在尝试使用此代码:
当我单击 imageButton 时,这将执行 goJournalArticles(View v) 方法:
public void goJournalArticles(View v) { new DownoadJournalsFinishedAsync().execute(); }
然后,我正在做一些事情,在此期间,我正在显示 progressDialog:
class DownoadJournalsFinishedAsync extends AsyncTask<String, String, ArrayList<String>> {
ProgressDialog dialog = new ProgressDialog(Journals.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog.setMessage("Loading Articles. Please wait...");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected ArrayList<String> doInBackground(String... aurl) {
String journalNameShort = localDatabase.getHistoryLastSelectedJournal();
int journalId = localDatabase.getJournalIdFromNameShort(journalNameShort);
ArrayList<String> result = new ArrayList<String>();
try {
infoCourrentIssue = serviceMDPI.JournalCurrentIssue(journalId);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int issue =infoCourrentIssue.getIssue();
int volume = infoCourrentIssue.getVolume();
ArrayList<Article> articles = GetCurrentIssue(journalId,volume,issue);
int size = articles.size();
for (int i=0;i<size;i++)
{
result.add(Html.fromHtml(articles.get(i).getTitle()).toString());
}
return result;
}
@Override
protected void onPostExecute(ArrayList<String> result) {
//View v = findViewById(R.id.Articles);
Intent myIntent = new Intent(getBaseContext(), JournalArticles.class);
myIntent.putExtra("articlesTitle", result);
startActivityForResult(myIntent, 0);
dialog.dismiss();
}
}
但是当我试图打开一个有意图的新活动时,我收到了这个错误:
03-05 12:08:47.724: E/AndroidRuntime(22249): FATAL EXCEPTION: main
03-05 12:08:47.724: E/AndroidRuntime(22249): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{milos.mdpi/milos.mdpi.JournalArticles}: java.lang.NullPointerException
03-05 12:08:47.724: E/AndroidRuntime(22249): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
03-05 12:08:47.724: E/AndroidRuntime(22249): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
03-05 12:08:47.724: E/AndroidRuntime(22249): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
03-05 12:08:47.724: E/AndroidRuntime(22249): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
03-05 12:08:47.724: E/AndroidRuntime(22249): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 12:08:47.724: E/AndroidRuntime(22249): at android.os.Looper.loop(Looper.java:150)
03-05 12:08:47.724: E/AndroidRuntime(22249): at android.app.ActivityThread.main(ActivityThread.java:4389)
03-05 12:08:47.724: E/AndroidRuntime(22249): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:08:47.724: E/AndroidRuntime(22249): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 12:08:47.724: E/AndroidRuntime(22249): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
03-05 12:08:47.724: E/AndroidRuntime(22249): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
03-05 12:08:47.724: E/AndroidRuntime(22249): at dalvik.system.NativeStart.main(Native Method)
03-05 12:08:47.724: E/AndroidRuntime(22249): Caused by: java.lang.NullPointerException
03-05 12:08:47.724: E/AndroidRuntime(22249): at android.app.Activity.findViewById(Activity.java:1732)
03-05 12:08:47.724: E/AndroidRuntime(22249): at milos.mdpi.JournalArticles.<init>(JournalArticles.java:13)
03-05 12:08:47.724: E/AndroidRuntime(22249): at java.lang.Class.newInstanceImpl(Native Method)
03-05 12:08:47.724: E/AndroidRuntime(22249): at java.lang.Class.newInstance(Class.java:1409)
03-05 12:08:47.724: E/AndroidRuntime(22249): at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
03-05 12:08:47.724: E/AndroidRuntime(22249): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1777)
03-05 12:08:47.724: E/AndroidRuntime(22249): ... 11 more