'java.lang.Class java.lang.Object.getClass()'是否为空对象引用?

时间:2019-05-19 20:46:29

标签: java android nullpointerexception retrofit2

我正在开发新闻应用程序,但遇到以下异常

import random
import os
import pygame
from pygame.locals import *
from pytmx.util_pygame import load_pygame
WHITE = (255, 255, 255)
GREEN = (20, 255, 140)
GREY = (210, 210 ,210)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
PURPLE = (255, 0, 255)

class Wall(pygame.sprite.Sprite):
  def __init__(self, x, y, width, height):
    pygame.sprite.Sprite.__init__(self)
    self.image = pygame.Surface([width, height])
    self.image.fill(blue)

    self.rect = self.image.get_rect()
    self.rect.y = y
    self.rect.x = x






pygame.init()

#Link Sprite

sprite = pygame.image.load(os.path.join(image_folder, "sprite.gif"))

sprite_rect = sprite.get_rect()

sprite_rect.centerx = (width//2)
sprite_rect.centery = (height//3)

#Display and Run Code

display_width = 800
display_height = 800

pygame.display.set_caption("Smash Bros Replica")

#PyTMX Code

gameMap = pytmx.load_pygame('gamemap.tmx')

def game_loop():
    gameExit = False
    while not gameExit:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
               gameExit = True

    # Drawing Map Data On The Screen
    for layer in gameMap.visible_layers:
        for x, y, gid, in layer:
            tile = gameMap.get_tile_image_by_gid(gid)
            gameScreen.blit(tile, (x * gameMap.tilewidth,
                                   y * gameMap.tileheight))
    pygame.display.update()
    clock.tick(30)

game_loop()











#Key Inputs for Link Sprite  
keyinput = pygame.key.get_pressed()
if keyinput[pygame.K_LEFT]:
  sprite_rect.centerx -= 10
elif keyinput[pygame.K_RIGHT]:
  sprite_rect.centerx += 10
elif keyinput[pygame.K_UP]:
  sprite_rect.centery -= 10
elif keyinput[pygame.K_DOWN]:
  sprite_rect.centery += 10

  screen.blit(sprite, sprite_rect)

  clock.tick(60)

pygame.quit()

在我的片段类中

在BBCSportsFragment.java文件下面

 Process: edgar.yodgorbek.sportnews, PID: 28111
     java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object
 reference
         at edgar.yodgorbek.sportnews.sportactivities.BBCSportFragment$1.onResponse(BBCSportFragment.java:69)
         at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
         at android.os.Handler.handleCallback(Handler.java:883)
         at android.os.Handler.dispatchMessage(Handler.java:100)
         at android.os.Looper.loop(Looper.java:214)
         at android.app.ActivityThread.main(ActivityThread.java:7116)
         at java.lang.reflect.Method.invoke(Native Method)
         at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)

0 个答案:

没有答案