简体   繁体   English

Android错误:调用一个空对象。 JSON /齐射

[英]Android Error: invoke a null object. JSON/Volley

Class : Time 上课时间

public class Time extends FragmentActivity {

public int LPassIN;
public int LPassOUT;
int secondPassed = 0;
Timer mytime = new Timer();


TimerTask mytask = new TimerTask() {
    public void run() {
        secondPassed++;


        if (secondPassed == 11) {
            secondPassed = 0;


            Convertion callConvertion = new Convertion();
            try {
                callConvertion.cnvrt();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            int donecnvrtin = callConvertion.donecnvrtin();
            int donecnvrtout = callConvertion.donecnvrtout();

            String PPassIN = Integer.toString(donecnvrtin);
            String PPassOUT = Integer.toString(donecnvrtout);



            Response.Listener<String> responseListener = new Response.Listener<String>() {

                @Override
                public void onResponse(String response) {

                    try {
                        JSONObject jsonResponse = new JSONObject(response);
                        boolean success = jsonResponse.getBoolean("success");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            };
            ServerI serv = new ServerI(PPassIN,PPassOUT,responseListener);
            RequestQueue queue = Volley.newRequestQueue(Time.this);


            if (LPassIN != donecnvrtin) {
                LPassIN = donecnvrtin;
                queue.add(serv);
                System.out.println(LPassIN);
            }

            if (LPassOUT != donecnvrtout) {
                LPassOUT = donecnvrtout;
                queue.add(serv);
                System.out.println(LPassOUT);
            }



        } else {

            System.out.println("Second : " + secondPassed);
        }
    }
};


public void start() {

    mytime.scheduleAtFixedRate(mytask, 1000, 1000);
}

public static void main() throws Exception {
    Time starter = new Time();
    starter.start();
}

} }

Error This is the Error i got 错误这是我得到的错误

07-20 04:16:05.878 2733-2733/com.example.kappa.servicedemo W/System:  ClassLoader referenced unknown path: /data/app/com.example.kappa.servicedemo-1/lib/x86
07-20 04:16:05.991 2733-2733/com.example.kappa.servicedemo W/art: Before  Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-20 04:16:06.088 2733-2775/com.example.kappa.servicedemo D/OpenGLRenderer:   Use EGL_SWAP_BEHAVIOR_PRESERVED: true

                                                                         [                                                                       07-20 04:16:06.091  2733: 2733 D/         ]
                                                                         HostConnection::get() New Host Connection established 0xac372530, tid 2733


                                                                         [ 07-20 04:16:06.130  2733: 2775 D/         ]
                                                                          HostConnection::get() New Host Connection established 0xb405c820, tid 2775
 07-20 04:16:06.132 2733-2775/com.example.kappa.servicedemo I/OpenGLRenderer: Initialized EGL, version 1.4
 07-20 04:16:06.160 2733-2775/com.example.kappa.servicedemo W/EGL_emulation: eglSurfaceAttrib not implemented
 07-20 04:16:06.160 2733-2775/com.example.kappa.servicedemo W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2462300, error=EGL_SUCCESS
 07-20 04:16:06.268 2733-2775/com.example.kappa.servicedemo W/EGL_emulation: eglSurfaceAttrib not implemented
 07-20 04:16:06.268 2733-2775/com.example.kappa.servicedemo W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2462c00, error=EGL_SUCCESS
 07-20 04:16:06.314 2733-2775/com.example.kappa.servicedemo V/RenderScript: 0xa1cb1000 Launching thread(s), CPUs 2
 07-20 04:16:07.104 2733-2776/com.example.kappa.servicedemo I/System.out: Second : 1
 07-20 04:16:08.104 2733-2776/com.example.kappa.servicedemo I/System.out: Second : 2
 07-20 04:16:09.104 2733-2776/com.example.kappa.servicedemo I/System.out: Second : 3
 07-20 04:16:09.601 2733-2775/com.example.kappa.servicedemo E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa2442700
 07-20 04:16:10.103 2733-2776/com.example.kappa.servicedemo I/System.out: Second : 4
 07-20 04:16:11.104 2733-2776/com.example.kappa.servicedemo I/System.out: Second : 5
 07-20 04:16:12.103 2733-2776/com.example.kappa.servicedemo I/System.out: Second : 6
 07-20 04:16:13.102 2733-2776/com.example.kappa.servicedemo I/System.out: Second : 7
 07-20 04:16:14.103 2733-2776/com.example.kappa.servicedemo I/System.out: Second : 8
 07-20 04:16:15.105 2733-2776/com.example.kappa.servicedemo I/System.out: Second : 9
 07-20 04:16:16.103 2733-2776/com.example.kappa.servicedemo I/System.out: Second : 10
 07-20 04:16:17.115 2733-2776/com.example.kappa.servicedemo E/AndroidRuntime: FATAL EXCEPTION: Timer-0
                                                                         Process: com.example.kappa.servicedemo, PID: 2733
                                                                         java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getCacheDir()' on a null object reference
                                                                             at android.content.ContextWrapper.getCacheDir(ContextWrapper.java:233)
                                                                             at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:43)
                                                                             at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:78)
                                                                             at com.example.kappa.servicedemo.Time$1.run(Time.java:66)
                                                                             at java.util.Timer$TimerImpl.run(Timer.java:284)
  07-20 04:16:17.198 2733-2775/com.example.kappa.servicedemo E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa2442150

                                                                  [ 07-20 04:16:17.213  1373: 2964 D/         ]
                                                                    HostConnection::get() New Host Connection established 0x9bc5da40, tid 2964                                  at java.util.Timer$TimerImpl.run(Timer.java:284)

why i got an error that indicate my request queue is a null object? 为什么我收到一个错误消息,指示我的请求队列是空对象? is my method wrong or anything? 我的方法有问题吗?

The app started,after countdown to 10,crash resulting the error 应用启动,倒数至10后崩溃,导致错误

Your code is requesting a directory which is not exist. 您的代码正在请求一个不存在的目录。 Therefor you are getting this null pointer at file or directory 因此,您将在文件或目录中获得此空指针

 'java.io.File android.content.Context.getCacheDir()'

Check your code 检查你的代码

` `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM