java.lang.NullPointerException.printStackTrace()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(272)

本文整理了Java中java.lang.NullPointerException.printStackTrace()方法的一些代码示例,展示了NullPointerException.printStackTrace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NullPointerException.printStackTrace()方法的具体详情如下:
包路径:java.lang.NullPointerException
类名称:NullPointerException
方法名:printStackTrace

NullPointerException.printStackTrace介绍

暂无

代码示例

代码示例来源:origin: aa112901/remusic

@Override
protected Void doInBackground(Void... params) {
  try {
    JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Billboard.billSongList(BILLBOARD_KING, 0, 3));
    JsonArray array = jsonObject.get("song_list").getAsJsonArray();
    for (int i = 0; i < array.size(); i++) {
      BillboardInfo billboardInfo = new BillboardInfo();
      billboardInfo.title = array.get(i).getAsJsonObject().get("title").toString();
      billboardInfo.author = array.get(i).getAsJsonObject().get("author").toString();
      billboardInfo.id = array.get(i).getAsJsonObject().get("artist_id").toString();
      items.add(billboardInfo);
    }
  } catch (NullPointerException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: aa112901/remusic

@Override
protected Void doInBackground(Integer... params) {
  JsonArray array = null;
  try {
    JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Billboard.billSongList(params[0], 0, 3));
    array = jsonObject.get("song_list").getAsJsonArray();
    for (int i = 0; i < array.size(); i++) {
      BillboardInfo billboardInfo = new BillboardInfo();
      billboardInfo.title = array.get(i).getAsJsonObject().get("title").toString();
      billboardInfo.author = array.get(i).getAsJsonObject().get("author").toString();
      billboardInfo.id = array.get(i).getAsJsonObject().get("artist_id").toString();
      items.add(billboardInfo);
    }
  } catch (NullPointerException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: cucumber/cucumber-jvm

@Override
public void stop() {
  try {
    if (containerInstance.isRunning()) {
      containerInstance.close();
    }
  } catch (NullPointerException npe) {
    System.err.println(STOP_EXCEPTION_MESSAGE);
    npe.printStackTrace(System.err);
  }
}

代码示例来源:origin: aa112901/remusic

@Override
protected Void doInBackground(Void... params) {
  if (NetworkUtils.isConnectInternet(mContext)) {
    isFromCache = false;
  }
  //推荐电台
  try {
    JsonObject list = HttpUtil.getResposeJsonObject("http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.8.1.0&channel=ppzs&operator=3&method=baidu.ting.plaza.index&cuid=89CF1E1A06826F9AB95A34DC0F6AAA14"
        , mContext, isFromCache);
    JsonObject object = list.get("result").getAsJsonObject();
    JsonArray radioArray = object.get("radio").getAsJsonObject().get("result").getAsJsonArray();
    JsonArray recommendArray = object.get("diy").getAsJsonObject().get("result").getAsJsonArray();
    JsonArray newAlbumArray = object.get("mix_1").getAsJsonObject().get("result").getAsJsonArray();
    for (int i = 0; i < 6; i++) {
      mRecomendList.add(MainApplication.gsonInstance().fromJson(recommendArray.get(i), RecommendListRecommendInfo.class));
      mNewAlbumsList.add(MainApplication.gsonInstance().fromJson(newAlbumArray.get(i), RecommendListNewAlbumInfo.class));
      mRadioList.add(MainApplication.gsonInstance().fromJson(radioArray.get(i), RecommendListRadioInfo.class));
    }
  } catch (NullPointerException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: aa112901/remusic

@Override
protected Integer doInBackground(Integer... params) {
  if (NetworkUtils.isConnectInternet(mContext)) {
    isFromCache = false;
  }
  //推荐电台
  try {
    JsonObject list = HttpUtil.getResposeJsonObject("http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.8.1.0&channel=ppzs&operator=3&method=baidu.ting.plaza.index&cuid=89CF1E1A06826F9AB95A34DC0F6AAA14"
        , mContext, isFromCache);
    JsonObject object = list.get("result").getAsJsonObject();
    JsonArray radioArray = object.get("radio").getAsJsonObject().get("result").getAsJsonArray();
    JsonArray recommendArray = object.get("diy").getAsJsonObject().get("result").getAsJsonArray();
    JsonArray newAlbumArray = object.get("mix_1").getAsJsonObject().get("result").getAsJsonArray();
    for (int i = 0; i < 6; i++) {
      mRecomendList.add(MainApplication.gsonInstance().fromJson(recommendArray.get(i), RecommendListRecommendInfo.class));
      mNewAlbumsList.add(MainApplication.gsonInstance().fromJson(newAlbumArray.get(i), RecommendListNewAlbumInfo.class));
      mRadioList.add(MainApplication.gsonInstance().fromJson(radioArray.get(i), RecommendListRadioInfo.class));
    }
  } catch (NullPointerException e) {
    e.printStackTrace();
  }
  return params[0];
}

代码示例来源:origin: stanfordnlp/CoreNLP

private void primeGs() {
 GrammaticalStructure gs = null;
 while (gs == null && tbIterator.hasNext()) {
  Tree t = tbIterator.next();
  // log.info("GsIterator: Next tree is");
  // log.info(t);
  if (t == null) {
   continue;
  }
  try {
   gs = params.getGrammaticalStructure(t, puncFilter, hf);
   origTrees.put(gs, t);
   next = gs;
   // log.info("GsIterator: Next tree is");
   // log.info(t);
   return;
  } catch (NullPointerException npe) {
   log.info("Bung tree caused below dump. Continuing....");
   log.info(t);
   npe.printStackTrace();
  }
 }
 next = null;
}

代码示例来源:origin: aa112901/remusic

public static MusicFileDownInfo getUrl(final Context context, final String id) {
  MusicFileDownInfo musicFileDownInfo = null;
  try {
    JsonArray jsonArray = HttpUtil.getResposeJsonObject(BMA.Song.songInfo(id).trim(), context, false).get("songurl")
        .getAsJsonObject().get("url").getAsJsonArray();
    int len = jsonArray.size();
    int downloadBit = 192;
    for (int i = len - 1; i > -1; i--) {
      int bit = Integer.parseInt(jsonArray.get(i).getAsJsonObject().get("file_bitrate").toString());
      if (bit == downloadBit) {
        musicFileDownInfo = MainApplication.gsonInstance().fromJson(jsonArray.get(i), MusicFileDownInfo.class);
      } else if (bit < downloadBit && bit >= 64) {
        musicFileDownInfo = MainApplication.gsonInstance().fromJson(jsonArray.get(i), MusicFileDownInfo.class);
      }
    }
  } catch (NumberFormatException e) {
    e.printStackTrace();
  } catch (JsonSyntaxException e) {
    e.printStackTrace();
  } catch (NullPointerException e) {
    e.printStackTrace();
  }
  return musicFileDownInfo;
}

代码示例来源:origin: aa112901/remusic

@Override
protected Void doInBackground(Void... params) {
  if (NetworkUtils.isConnectInternet(mContext)) {
    isFromCache = false;
  }
  try {
    JsonArray rray = HttpUtil.getResposeJsonObject(BMA.focusPic(7), mContext, isFromCache).get("pic").getAsJsonArray();
    int en = rray.size();
    Gson gson = new Gson();
    imageNet.clear();
    for (int i = 0; i < en; i++) {
      FocusItemInfo focusItemInfo = gson.fromJson(rray.get(i), FocusItemInfo.class);
      if (focusItemInfo != null) {
        imageNet.add(focusItemInfo.getRandpic());
      } else {
        imageNet.add("");
      }
    }
  } catch (NullPointerException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: android-hacker/VirtualXposed

private void deliverNewIntentLocked(ActivityRecord sourceRecord, ActivityRecord targetRecord, Intent intent) {
  if (targetRecord == null) {
    return;
  }
  String creator = sourceRecord != null ? sourceRecord.component.getPackageName() : "android";
  try {
    targetRecord.process.client.scheduleNewIntent(creator, targetRecord.token, intent);
  } catch (RemoteException e) {
    e.printStackTrace();
  } catch (NullPointerException npe) {
    npe.printStackTrace();
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Runs this session by reading a string, tagging it, and writing
 * back the result.  The input should be a single line (no embedded
 * newlines), which represents a whole sentence or document.
 */
@Override
public void run() {
 if (DEBUG) {log.info("Created new session");}
 try {
  String input = in.readLine();
  if (DEBUG) {
   EncodingPrintWriter.err.println("Receiving: \"" + input + '\"', charset);
  }
  if (! (input == null)) {
   String output = tagger.apply(input);
   if (DEBUG) {
    EncodingPrintWriter.err.println("Sending: \"" + output + '\"', charset);
   }
   out.print(output);
   out.flush();
  }
  close();
 } catch (IOException e) {
  log.info("MaxentTaggerServer:Session: couldn't read input or error running POS tagger");
  e.printStackTrace(System.err);
 } catch (NullPointerException npe) {
  log.info("MaxentTaggerServer:Session: connection closed by peer");
  npe.printStackTrace(System.err);
 }
}

代码示例来源:origin: h2oai/h2o-3

e.printStackTrace();

代码示例来源:origin: apache/ignite

@Override public void run()  {
    while (true) {
      try (Transaction tx = client1.transactions().txStart()) {
        /** Empty transaction, just testing {@link TransactionProxyImpl#leave} */
      }
      catch (NullPointerException e) {
        e.printStackTrace();
        ex.compareAndSet(null, e);
        latch.countDown();
        break;
      }
    }
  }
}, 1, "tx-thread");

代码示例来源:origin: stanfordnlp/CoreNLP

} catch (NullPointerException npe) {
 log.info("NERServer:Session: connection closed by peer");
 npe.printStackTrace(System.err);

代码示例来源:origin: btraceio/btrace

private void commandLoop(CommandListener listener)
    throws IOException {
  assert ois != null : "null input stream?";
  final AtomicBoolean exited = new AtomicBoolean(false);
  while (true) {
    try {
      Command cmd = WireIO.read(ois);
      if (debug) {
        debugPrint("received " + cmd);
      }
      listener.onCommand(cmd);
      if (cmd.getType() == Command.EXIT) {
        debugPrint("received EXIT cmd");
        return;
      }
    } catch (IOException e) {
      if (exited.compareAndSet(false, true)) listener.onCommand(new ExitCommand(-1));
      throw e;
    } catch (NullPointerException e) {
      e.printStackTrace();
      if (exited.compareAndSet(false, true))listener.onCommand(new ExitCommand(-1));
    }
  }
}

代码示例来源:origin: Rukey7/MvpApp

@Override
public void onSelectedFilePaths(String[] files) {
  if (files == null || files.length == 0) {
    return;
  }
  // 这里改成只取第一项
  String dFiles = StringUtils.replaceFilePath(files[0]);
  if (isPersistent()) {
    persistString(dFiles);
  }
  try {
    getOnPreferenceChangeListener().onPreferenceChange(this, dFiles);
  } catch (NullPointerException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Command(shortDescription = "Sets the eye-height of the player", runOnServer = true,
    requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String playerEyeHeight(@Sender EntityRef client, @CommandParam("eye-height") float amount) {
  EntityRef player = client.getComponent(ClientComponent.class).character;
  try {
    GazeMountPointComponent gazeMountPointComponent = player.getComponent(GazeMountPointComponent.class);
    if (gazeMountPointComponent != null) {
      float prevHeight = gazeMountPointComponent.translate.y;
      gazeMountPointComponent.translate.y = amount;
      Location.removeChild(player, gazeMountPointComponent.gazeEntity);
      Location.attachChild(player, gazeMountPointComponent.gazeEntity, gazeMountPointComponent.translate, new Quat4f(Quat4f.IDENTITY));
      player.saveComponent(gazeMountPointComponent);
      return "Eye-height of player set to " + amount + " (was " + prevHeight + ")";
    }
    return "";
  } catch (NullPointerException e) {
    e.printStackTrace();
    return "";
  }
}

代码示例来源:origin: Justson/AgentWeb

public void onPageFinished(WebView view) {
  if (!mIsOnReceivedTitle && mWebChromeClient != null) {
    WebBackForwardList list = null;
    try {
      list = view.copyBackForwardList();
    } catch (NullPointerException e) {
      if (LogUtils.isDebug()) {
        e.printStackTrace();
      }
    }
    if (list != null
        && list.getSize() > 0
        && list.getCurrentIndex() >= 0
        && list.getItemAtIndex(list.getCurrentIndex()) != null) {
      String previousTitle = list.getItemAtIndex(list.getCurrentIndex()).getTitle();
      mWebChromeClient.onReceivedTitle(view, previousTitle);
    }
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test(timeout = 5000)
public void createOnSubscribeThrowsRuntimeException() {
  List<Throwable> errors = TestHelper.trackPluginErrors();
  try {
    Completable c = Completable.unsafeCreate(new CompletableSource() {
      @Override
      public void subscribe(CompletableObserver observer) {
        throw new TestException();
      }
    });
    c.blockingAwait();
    Assert.fail("Did not throw exception");
  } catch (NullPointerException ex) {
    if (!(ex.getCause() instanceof TestException)) {
      ex.printStackTrace();
      Assert.fail("Did not wrap the TestException but it returned: " + ex);
    }
    TestHelper.assertUndeliverable(errors, 0, TestException.class);
  } finally {
    RxJavaPlugins.reset();
  }
}

代码示例来源:origin: voldemort/voldemort

/**
 * Checks if the streamingClient stays calm and not throw NPE when calling
 * commit before it has been initialized
 */
@Test
public void testUnInitializedClientPreventNPE() {
  Props property = new Props();
  property.put("streaming.platform.bootstrapURL", SERVER_LOCAL_URL + serverPorts[0]);
  StreamingClientConfig config = new StreamingClientConfig(property);
  BaseStreamingClient streamer = new BaseStreamingClient(config);
  try {
    streamer.commitToVoldemort();
  } catch (NullPointerException e) {
    e.printStackTrace();
    Assert.fail("Should not throw NPE at this stage even though streamingSession not initialized");
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Command(shortDescription = "Sets the height of the player", runOnServer = true,
    requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String playerHeight(@Sender EntityRef client, @CommandParam("height") float amount) {
  try {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    if (move != null) {
      float prevHeight = move.height;
      move.height = amount;
      clientComp.character.saveComponent(move);
      LocationComponent loc = client.getComponent(LocationComponent.class);
      Vector3f currentPosition = loc.getWorldPosition();
      clientComp.character
          .send(new CharacterTeleportEvent(new Vector3f(currentPosition.getX(), currentPosition.getY() + (amount - prevHeight) / 2, currentPosition.getZ())));
      physics.removeCharacterCollider(clientComp.character);
      physics.getCharacterCollider(clientComp.character);
      return "Height of player set to " + amount + " (was " + prevHeight + ")";
    }
    return "";
  } catch (NullPointerException e) {
    e.printStackTrace();
    return "";
  }
}

相关文章