我一直在寻找答案,因为我看到其他人有同样的问题。执行doInBackground时发生错误,但我无法在此处找到解决问题的方法。
这是错误:
07-07 15:56:30.060: E/AndroidRuntime(26940): FATAL EXCEPTION: AsyncTask #1
07-07 15:56:30.060: E/AndroidRuntime(26940): Process: com.dusandimitrijevic.filmovipreporuke, PID: 26940
07-07 15:56:30.060: E/AndroidRuntime(26940): java.lang.RuntimeException: An error occured while executing doInBackground()
07-07 15:56:30.060: E/AndroidRuntime(26940): at android.os.AsyncTask$3.done(AsyncTask.java:300)
07-07 15:56:30.060: E/AndroidRuntime(26940): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
07-07 15:56:30.060: E/AndroidRuntime(26940): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
07-07 15:56:30.060: E/AndroidRuntime(26940): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
07-07 15:56:30.060: E/AndroidRuntime(26940): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
07-07 15:56:30.060: E/AndroidRuntime(26940): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-07 15:56:30.060: E/AndroidRuntime(26940): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-07 15:56:30.060: E/AndroidRuntime(26940): at java.lang.Thread.run(Thread.java:818)
07-07 15:56:30.060: E/AndroidRuntime(26940): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.Parse.getParseDir(Parse.java:304)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseObject.getFromDisk(ParseObject.java:667)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseUser$10.then(ParseUser.java:1056)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseUser$10.then(ParseUser.java:1003)
07-07 15:56:30.060: E/AndroidRuntime(26940): at bolts.Task$14.run(Task.java:796)
07-07 15:56:30.060: E/AndroidRuntime(26940): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
07-07 15:56:30.060: E/AndroidRuntime(26940): at bolts.Task.completeAfterTask(Task.java:787)
07-07 15:56:30.060: E/AndroidRuntime(26940): at bolts.Task.continueWithTask(Task.java:599)
07-07 15:56:30.060: E/AndroidRuntime(26940): at bolts.Task.continueWithTask(Task.java:610)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:1003)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseUser.access$800(ParseUser.java:26)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseUser$9.then(ParseUser.java:996)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseUser$9.then(ParseUser.java:993)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.TaskQueue.enqueue(TaskQueue.java:61)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:993)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:956)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseQuery.getUserAsync(ParseQuery.java:914)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseQuery$3.call(ParseQuery.java:1172)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseQuery$3.call(ParseQuery.java:1169)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseQuery.doWithRunningCheck(ParseQuery.java:1108)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseQuery.findAsync(ParseQuery.java:1169)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseQuery.findInBackground(ParseQuery.java:1137)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.parse.ParseQuery.find(ParseQuery.java:957)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.dusandimitrijevic.filmovipreporuke.MainActivity$RemoteDataTask.doInBackground(MainActivity.java:68)
07-07 15:56:30.060: E/AndroidRuntime(26940): at com.dusandimitrijevic.filmovipreporuke.MainActivity$RemoteDataTask.doInBackground(MainActivity.java:1)
07-07 15:56:30.060: E/AndroidRuntime(26940): at android.os.AsyncTask$2.call(AsyncTask.java:288)
07-07 15:56:30.060: E/AndroidRuntime(26940): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-07 15:56:30.060: E/AndroidRuntime(26940): ... 4 more
07-07 15:56:32.002: I/Choreographer(26940): Skipped 96 frames! The application may be doing too much work on its main thread.
07-07 15:56:32.162: E/OpenGLRenderer(26940): SFEffectCache:clear(), mSize = 0
07-07 15:56:32.222: E/WindowManager(26940): android.view.WindowLeaked: Activity com.dusandimitrijevic.filmovipreporuke.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{34b0c646 V.E..... R......D 0,0-1002,475} that was originally added here
07-07 15:56:32.222: E/WindowManager(26940): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:465)
07-07 15:56:32.222: E/WindowManager(26940): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:277)
07-07 15:56:32.222: E/WindowManager(26940): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
07-07 15:56:32.222: E/WindowManager(26940): at android.app.Dialog.show(Dialog.java:312)
07-07 15:56:32.222: E/WindowManager(26940): at com.dusandimitrijevic.filmovipreporuke.MainActivity$RemoteDataTask.onPreExecute(MainActivity.java:55)
07-07 15:56:32.222: E/WindowManager(26940): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
07-07 15:56:32.222: E/WindowManager(26940): at android.os.AsyncTask.execute(AsyncTask.java:535)
07-07 15:56:32.222: E/WindowManager(26940): at com.dusandimitrijevic.filmovipreporuke.MainActivity.onCreate(MainActivity.java:30)
07-07 15:56:32.222: E/WindowManager(26940): at android.app.Activity.performCreate(Activity.java:6289)
07-07 15:56:32.222: E/WindowManager(26940): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
07-07 15:56:32.222: E/WindowManager(26940): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
07-07 15:56:32.222: E/WindowManager(26940): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
07-07 15:56:32.222: E/WindowManager(26940): at android.app.ActivityThread.access$900(ActivityThread.java:177)
07-07 15:56:32.222: E/WindowManager(26940): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
07-07 15:56:32.222: E/WindowManager(26940): at android.os.Handler.dispatchMessage(Handler.java:102)
07-07 15:56:32.222: E/WindowManager(26940): at android.os.Looper.loop(Looper.java:145)
07-07 15:56:32.222: E/WindowManager(26940): at android.app.ActivityThread.main(ActivityThread.java:5942)
07-07 15:56:32.222: E/WindowManager(26940): at java.lang.reflect.Method.invoke(Native Method)
07-07 15:56:32.222: E/WindowManager(26940): at java.lang.reflect.Method.invoke(Method.java:372)
07-07 15:56:32.222: E/WindowManager(26940): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
07-07 15:56:32.222: E/WindowManager(26940): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
以下是MainActivity的代码:
public class MainActivity extends MyActionBar {
ListView listView;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ListViewAdapter adapter;
private List<Filmovi> naslov = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new RemoteDataTask().execute();
}
@Override
protected int getLayoutResourceId() {
return R.layout.activity_main;
}
// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(MainActivity.this);
// Set progressdialog title
mProgressDialog.setTitle("Horor Filmovi - Analize i Ocene");
// Set progressdialog message
mProgressDialog.setMessage("Ucitavanje...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create the array
naslov = new ArrayList<Filmovi>();
try {
// Locate the class table named "Film" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"Film");
// Locate the column named "ranknum" in Parse.com and order list
// by ascending
query.orderByAscending("ranknum");
ob = query.find();
for (ParseObject ime : ob) {
// Locate images in slike column
ParseFile image = (ParseFile) ime.get("slika");
Filmovi map = new Filmovi();
map.setIme((String) ime.get("naslov"));
map.setSlika(image.getUrl());
naslov.add(map);
}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
listView = (ListView) findViewById(R.id.listView);
// Pass the results into ListViewAdapter.java
adapter = new ListViewAdapter(MainActivity.this,
naslov);
// Binds the Adapter to the ListView
listView.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
}
这是初始化:
public class ParseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Add your initialization code here
Parse.enableLocalDatastore(this);
Parse.initialize(this, "MY IDENTIFICATION ID", "CLIENT KEY");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// If you would like all objects to be private by default, remove,this line.
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}
任何人都知道这里有什么问题?