标签: runtimeexception

PySpark 相当于将常量数组作为列添加到数据帧中

以下代码适用于 Scala-Spark。

scala> val ar = Array("oracle", "java")
ar: Array[String] = Array(oracle, java)

scala> df.withColumn("tags", lit(ar)).show(false)
+------+---+----------+----------+--------------+
|name  |age|role      |experience|tags          |
+------+---+----------+----------+--------------+
|John  |25 |Developer |2.56      |[oracle, java]|
|Scott |30 |Tester    |5.2       |[oracle, java]|
|Jim   |28 |DBA       |3.0       |[oracle, java]|
|Mike  |35 |Consultant|10.0      |[oracle, java]|
|Daniel|26 |Developer |3.2       |[oracle, java]|
|Paul  |29 |Tester    |3.6       |[oracle, java]|
|Peter |30 |Developer |6.5       |[oracle, java]|
+------+---+----------+----------+--------------+
Run Code Online (Sandbox Code Playgroud)

如何在 PySpark 中获得相同的行为?我尝试了以下方法,但它不起作用并引发 Java 错误。

from pyspark.sql.types import *

tag = ["oracle", "java"]
df2.withColumn("tags", lit(tag)).show()
Run Code Online (Sandbox Code Playgroud)

:java.lang.RuntimeException:不支持的文字类型类java.util.ArrayList [oracle,java]

arrays dataframe runtimeexception apache-spark pyspark

4
推荐指数
1
解决办法
5902
查看次数

为什么我的活动在按下主页按钮时会崩溃?

在这一点上,我很沮丧.我已经研究了几天,甚至无法隔离任何超出游标问题的东西.我正在扩展ListActivity并在OnCreate方法中使用startManagingCursor(newcursor).这是在按下主页按钮时运行和崩溃的代码(数据库已经填满):

private void loadAlbums() {
    try {
        newcursor = mDbHelper.getAlbumTitlesCursor();
        dbalbumadapter = new AlbumListCursorAdapter(this, newcursor);
        setListAdapter(dbalbumadapter);
        }
    catch (SQLiteException s) {
        newcursor = null;
        fetchalbums = new FetchAlbumsTask().execute();
        }
    current_view = ALBUMTITLE_VIEW;
}
Run Code Online (Sandbox Code Playgroud)

这是错误日志:

02-03 13:41:42.379: WARN/dalvikvm(340): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
02-03 13:41:42.389: ERROR/AndroidRuntime(340): Uncaught handler: thread main exiting due to uncaught exception

02-03 13:41:42.590: ERROR/AndroidRuntime(340): java.lang.RuntimeException: Unable to stop activity {com.skip.ngRCv2/com.skip.ngRCv2.ngRC}: java.lang.RuntimeException: Unable to stop activity {com.skip.ngRCv2/com.skip.ngRCv2.MusicLibraryActivity}: java.lang.NullPointerException
02-03 13:41:42.590: ERROR/AndroidRuntime(340):     at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3227)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): …
Run Code Online (Sandbox Code Playgroud)

android cursor nullpointerexception listactivity runtimeexception

3
推荐指数
1
解决办法
4345
查看次数

AlertDialog.show()上的RuntimeException

当我想在活动开始时显示alertdialog时,我不断收到异常.我想不通为什么?我真的很感激解释.

代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    if (!isInternetConnectionAvailable()) {
        AlertDialog alert = new AlertDialog.Builder(getApplicationContext()).create();
        alert.setMessage("TEST DIALOG!!!");
        alert.show();
    }
...
Run Code Online (Sandbox Code Playgroud)

03-19 16:04:33.933:ERROR/AndroidRuntime(15145):FATAL EXCEPTION:main 03-19 16:04:33.933:ERROR/AndroidRuntime(15145):java.lang.RuntimeException:无法启动活动ComponentInfo {de. droidgroup.THMInfo/de.droidgroup.THMInfo.Activities.StartActivity}:android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null不适用于应用程序03-19 16:04:33.933:ERROR/AndroidRuntime(15145 ):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)03-19 16:04:33.933:ERROR/AndroidRuntime(15145):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)03- 19 16:04:33.933:ERROR/AndroidRuntime(15145):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)03-19 16:04:33.933:ERROR/AndroidRuntime(15145):at android.app .ActivityThread $ H.handleMessage(ActivityThread.java:2033)03-19 16:04:33.933:ERROR/AndroidRuntime(15145):at android.os.Handler.dispatchMessage(Handler.java:99)03-19 16:04 :33.933:ERROR/AndroidRuntime(15145):在android.os.Looper.loop(Looper.java:123)03-19 16:04:33.933:ERROR/AndroidRuntime(15145):在android.app.ActivityThread.main(ActivityThread.java:4627)03 -19 16:04:33.933:ERROR/AndroidRuntime(15145):at java.lang.reflect.Method.invokeNative(Native Method)03-19 16:04:33.933:ERROR/AndroidRuntime(15145):at java.lang. reflect.Method.invoke(Method.java:521)03-19 16:04:33.933:ERROR/AndroidRuntime(15145):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:858)03 -19 16:04:33.933:ERROR/AndroidRuntime(15145):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)03-19 16:04:33.933:ERROR/AndroidRuntime(15145): at dalvik.system.NativeStart.main(Native Method)03-19 16:04:33.933:ERROR/AndroidRuntime(15145):引起:android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null不适用于应用03-19 16:04:33.933:ERROR/AndroidRuntime(15145):在android.view.ViewRoot.setView(ViewRoot.java:509)03-19 16:04:33.933:ER ROR/AndroidRuntime(15145):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)03-19 16:04:33.933:ERROR/AndroidRuntime(15145):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java) :91)03-19 16:04:33.933:ERROR/AndroidRuntime(15145):在android.app.Dialog.show(Dialog.java:241)03-19 16:04:33.933:ERROR/AndroidRuntime(15145): …

android runtimeexception android-alertdialog

3
推荐指数
1
解决办法
9115
查看次数

在没有外部SD卡的情况下缓存位图

没有外部SD卡,图像不会在内部存储器上缓存并在设备上崩溃.我尝试过我所知道的,没有任何效果.这是ImageCache.java

  package com.minecraftpix.android.bitmapfun.util;

  import com.minecraftpix.BuildConfig;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.util.LruCache;
import android.util.Log;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.SoftReference;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashSet;
import java.util.Iterator;


public class ImageCache {
private static final String TAG = "ImageCache";

// Default memory cache size in kilobytes
private static final int DEFAULT_MEM_CACHE_SIZE = 1024 * 5; …
Run Code Online (Sandbox Code Playgroud)

java android caching nullpointerexception runtimeexception

3
推荐指数
1
解决办法
2700
查看次数

为什么Java在运行时检查类型与转换的不兼容性,并且在编译时键入不匹配转换?

假设有2个班级.并Child扩展Parent.

public class Parent {}
Run Code Online (Sandbox Code Playgroud)

public class Child extends Parent {}
Run Code Online (Sandbox Code Playgroud)

我知道以下代码不正确:

Child obj = new Parent(); // causes java.lang.Error
Run Code Online (Sandbox Code Playgroud)

要么

Child obj = (Child) new Parent(); // causes java.lang.ClassCastException
Run Code Online (Sandbox Code Playgroud)

但我不明白为什么我在第一种情况下得到编译错误,在第二种情况下得到运行时异常.毕竟,父母永远不能转换或投射到孩子身上.为什么在编译时没有检查第二种情况?

我会非常感谢一个明确而合理的想法!

java compiler-errors runtimeexception

3
推荐指数
1
解决办法
887
查看次数

未捕获自定义RuntimeException

我有自己的ApplicationException女巫,扩展了RuntimeException:

package com.haslerrail.aura.common.exception;

public class ApplicationException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    private final ErrorCode errorCode;

    private final Object[] arguments;

    public ApplicationException(final ErrorCode errorCode, final Object... arguments) {
        super();
        this.errorCode = errorCode;
        this.arguments = arguments;
    }

    public ErrorCode getErrorCode() {
        return errorCode;
    }

    public Object[] getArguments() {
        return arguments;
    }

}
Run Code Online (Sandbox Code Playgroud)

此异常将由我的无状态bean引发:

public void doSomething()
        throws IOException, ApplicationException, InternalException {
    if (true) {
        throw new ApplicationException(ErrorCode.FILE_TYPE_NOT_SUPPORTED, "test");
    }
}
Run Code Online (Sandbox Code Playgroud)

我想通过我的sessionScoped bean捕获此runtimeException:

public void doXXX(final FileUploadEvent event) …
Run Code Online (Sandbox Code Playgroud)

java exception-handling java-ee runtimeexception

3
推荐指数
2
解决办法
1065
查看次数

为什么ArrayStoreException是RuntimeException?

假设我们有以下程序:

class Fruit {}

class Apple extends Fruit {} 

class Jonathan extends Apple {} 

class Orange extends Fruit {} 

public class Main { 
    public static void main(String[] args) { 
        Fruit[] fruit = new Apple[10];

        try { 
            fruit[0] = new Fruit(); // ArrayStoreException 
            fruit[0] = new Orange(); // ArrayStoreException 
        } catch(Exception e) { System.out.println(e); } 
    } 
}
Run Code Online (Sandbox Code Playgroud)

基于Java文档:

抛出以指示已尝试将错误类型的对象存储到对象数组中.

我在这里读到了

创建数组时,它会记住它要存储的数据类型.

如果数组记住它包含的数据类型,则意味着它知道它包含的数据类型.但是我发布的代码片段是正确编译的,所以在编译时,数组显然不知道包含什么类型.

我的问题是:

  1. 为什么ArrayStoreException只在运行时抛出?

  2. 编译器缺少哪些信息来实现该分配是不可能的?

  3. 有没有这样的代码是正确的,所以没有ArrayStoreException抛出?

java arrays exception-handling exception runtimeexception

3
推荐指数
1
解决办法
397
查看次数

RuntimeException(Chromecast)

我尝试配置Chromecast,但得到了RuntimeException并且没有理解原因.这是来自Fabric的日志:

致命异常:java.lang.RuntimeException:无法启动活动ComponentInfo {....activity.TVActivityPhone}:java.lang.RuntimeException:com.google.android.gms.dynamite.DynamiteModule $ zza:远程加载失败.没有发现本地回退.在Android.app.A活动中的android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)android.app.A活动.活动(活动传递.) .ActivityThread $ H.handleMessage(ActivityThread.java:1584)在android.app.Loper.loop(Looper.java:194)的android.app.Handler.dispatchMessage(Handler.java:111)android.app.ActivityThread. main(ActivityThread.java:5877)位于java.lang.reflect.Method.invoke(Method.java)的java.lang.reflect.Method.invoke(Method.java:372),位于com.android.internal.os.ZygoteInit com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)中的$ MethodAndArgsCaller.run(ZygoteInit.java:1020)由java.lang.RuntimeException引起:com.google.android.gms.dynamite.DynamiteModule $ zza:远程加载失败.没有发现本地回退.

这是我的代码:

protected void configureCast() {
        mCastContext = CastContext.getSharedInstance(this); // here I've got RuntimeException
        if(mCastContext != null) mCastSession = mCastContext.getSessionManager().getCurrentCastSession();
        mSessionManagerListener = new CastSessionManagerListener(this);
        mSessionManagerListener.setCastConnectionListener(mCastConnectionListener);
    }
Run Code Online (Sandbox Code Playgroud)

这是build.gradle:

    compile 'com.google.android.gms:play-services-gcm:10.2.0'
    compile 'com.google.android.gms:play-services-analytics:10.2.0'
    compile 'com.google.android.gms:play-services-location:10.2.0'
    compile 'com.google.android.gms:play-services-cast-framework:10.2.0'
Run Code Online (Sandbox Code Playgroud)

有帮助吗?

android runtimeexception chromecast

3
推荐指数
1
解决办法
1477
查看次数

使用 Glide Image Load setDataSource 的运行时异常失败:状态 =

我正在使用 Glide 从我的手机内存中加载图像。我的图像视图定义为:

   ImageView ivx=(ImageView)view.findViewById(R.id.ivx);
Run Code Online (Sandbox Code Playgroud)

使用 Glide 将手机中的图像加载到图像视图中的代码是:

  Glide.with(getActivity()).load(new File("/storage/emulated/0/somefolder/MEDIA/PROFILEIMAGES/PROFILE_image1.jpg").toString())
            .listener(new RequestListener<String, GlideDrawable>() {
                @Override
                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                    Log.e("xmx1","Error "+e.toString());
                    return false;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    Log.e("xmx1","no Error ");
                    return false;
                }
            })
            .into(ivx);
Run Code Online (Sandbox Code Playgroud)

我一直面临的问题是这段代码抛出了一个异常:

  Error java.lang.RuntimeException: setDataSource failed: status = 0x80000000
Run Code Online (Sandbox Code Playgroud)

我检查了文件,文件在文件夹中!但是 Glide 并没有将图像文件加载到图像视图中!

有人可以告诉我我做错了什么!

提前致谢

java android runtimeexception android-glide

3
推荐指数
1
解决办法
4460
查看次数

抛出RuntimeException时,Java期望返回值

为什么这不编译(尝试使用java 8和java 10)?它会产生一个缺少的返回语句错误.

 public class CompilerIssue {
   public boolean run() {
     throwIAE();
     // Missing return statement
   }

   public void throwIAE() {
     throw new IllegalStateException("error");
   }
 }
Run Code Online (Sandbox Code Playgroud)

java aop javac runtimeexception

3
推荐指数
2
解决办法
188
查看次数