显示java.lang.NullPointerException:试图调用虚拟方法java.io.File中com.parse.ParsePlugins.getParseDir()“在空对象引用 [英] java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference

查看:731
本文介绍了显示java.lang.NullPointerException:试图调用虚拟方法java.io.File中com.parse.ParsePlugins.getParseDir()“在空对象引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图加载从解析 A类,但是应用程序一旦我启动它崩溃了!
这里是code:

Trying to load a class from Parse , however the app crashes as soon I launch it! Here is the code:

 ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_big_board);
    new RemoteDataTask().execute();

}

private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        mProgressDialog = new ProgressDialog(BigBoard.this);
        mProgressDialog.setTitle("Parse.com Simple ListView Tutorial");
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        // Locate the class table named "Country" in Parse.com
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                "Country");
        query.orderByDescending("_created_at");
        try {
            ob = query.find();
        } 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 an ArrayAdapter
        adapter = new ArrayAdapter<String>(BigBoard.this,
                R.layout.listview_item);
        // Retrieve object "name" from Parse.com database
        for (ParseObject country : ob) {
            adapter.add((String) country.get("Name"));
        }
        // Binds the Adapter to the ListView
        listview.setAdapter(adapter);
        // Close the progressdialog
        mProgressDialog.dismiss();
        // Capture button clicks on ListView items
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // Send single item click data to SingleItemView Class
                Intent i = new Intent(BigBoard.this,
                        SingleItemView.class);
                // Pass data "name" followed by the position
                i.putExtra("name", ob.get(position).getString("name")
                        .toString());
                // Open SingleItemView.java Activity
                startActivity(i);
            }
        });
    }
}

这是我在logcat中获得:

And this is what I obtain in the logcat :

> 10-22 20:40:18.705  12588-12872/obx.com.futurister E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #3
    Process: obx.com.futurister, PID: 12588
    java.lang.RuntimeException: An error occurred while executing doInBackground()
            at android.os.AsyncTask$3.done(AsyncTask.java:309)
            at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
            at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
            at java.util.concurrent.FutureTask.run(FutureTask.java:242)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
            at java.lang.Thread.run(Thread.java:818)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
            at com.parse.Parse.getParseDir(Parse.java:315)
            at com.parse.ParseCorePlugins.getCurrentUserController(ParseCorePlugins.java:129)
            at com.parse.ParseUser.getCurrentUserController(ParseUser.java:55)
            at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:888)
            at com.parse.ParseQuery.getUserAsync(ParseQuery.java:938)
            at com.parse.ParseQuery$3.call(ParseQuery.java:1196)
            at com.parse.ParseQuery$3.call(ParseQuery.java:1193)
            at com.parse.ParseQuery.doWithRunningCheck(ParseQuery.java:1132)
            at com.parse.ParseQuery.findAsync(ParseQuery.java:1193)
            at com.parse.ParseQuery.findInBackground(ParseQuery.java:1161)
            at com.parse.ParseQuery.find(ParseQuery.java:981)
            at obx.com.futurister.BigBoard$RemoteDataTask.doInBackground(BigBoard.java:66)
            at obx.com.futurister.BigBoard$RemoteDataTask.doInBackground(BigBoard.java:44)
            at android.os.AsyncTask$2.call(AsyncTask.java:295)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
            at java.lang.Thread.run(Thread.java:818)
10-22 20:40:18.857  12588-12619/obx.com.futurister E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xb3a1fb90
10-22 20:40:18.955  12588-12619/obx.com.futurister E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xa96acbb0
10-22 20:40:18.996  12588-12588/obx.com.futurister E/WindowManager﹕ android.view.WindowLeaked: Activity obx.com.futurister.BigBoard has leaked window com.android.internal.policy.PhoneWindow$DecorView{a0f50b2 V.E...... R......D 0,0-1026,538} that was originally added here
            at android.view.ViewRootImpl.<init>(ViewRootImpl.java:368)
            at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
            at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
            at android.app.Dialog.show(Dialog.java:319)
            at obx.com.futurister.BigBoard$RemoteDataTask.onPreExecute(BigBoard.java:56)
            at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:604)
            at android.os.AsyncTask.execute(AsyncTask.java:551)
            at obx.com.futurister.BigBoard.onCreate(BigBoard.java:40)
            at android.app.Activity.performCreate(Activity.java:6237)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
            at android.app.ActivityThread.-wrap11(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

猜测其与 doInBackground()法的问题?我缺少的东西吗?请帮帮忙,谢谢

guess its the problem with the doInBackground() method? Am I missing something? Please help , Thanks

推荐答案

根据您的评论我猜你没有初始化的解析。
https://parse.com/apps/quickstart#parse_data/mobile/android /本地/现有

Based on your comment I'm guessing you haven't initialized Parse. https://parse.com/apps/quickstart#parse_data/mobile/android/native/existing

   public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        // Enable Local Datastore.
        Parse.enableLocalDatastore(this);

        // Register any ParseObject subclass. Must be done before calling Parse.initialize()
        ParseObject.registerSubclass(YourClass.class);

        Parse.initialize(this, "APPLICATION_ID", "CLIENT_KEY");    
    }
}

请确保您的应用程序类添加到清单

Make sure you add your App class to the manifest

这篇关于显示java.lang.NullPointerException:试图调用虚拟方法java.io.File中com.parse.ParsePlugins.getParseDir()“在空对象引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆