标签: runtimeexception

Android java.lang.RuntimeException:无法实例化活动

我目前卡住了Logcat的以下错误.我已经查看了其他十多个与此问题类似的帖子,但找不到我的问题的解决方案.

03-22 17:55:58.777: E/Trace(1172): error opening trace file: No such file or directory (2)
03-22 17:55:58.947: E/AndroidRuntime(1172): FATAL EXCEPTION: main
03-22 17:55:58.947: E/AndroidRuntime(1172): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.schoolwork.capstoneproject/com.schoolwork.capstoneproject.StartingPoint}: java.lang.NullPointerException
03-22 17:55:58.947: E/AndroidRuntime(1172):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
03-22 17:55:58.947: E/AndroidRuntime(1172):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-22 17:55:58.947: E/AndroidRuntime(1172):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-22 17:55:58.947: E/AndroidRuntime(1172):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-22 17:55:58.947: E/AndroidRuntime(1172):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 17:55:58.947: E/AndroidRuntime(1172):     at android.os.Looper.loop(Looper.java:137)
03-22 17:55:58.947: E/AndroidRuntime(1172):     at android.app.ActivityThread.main(ActivityThread.java:5039)
03-22 17:55:58.947: E/AndroidRuntime(1172):     at java.lang.reflect.Method.invokeNative(Native Method)
03-22 17:55:58.947: E/AndroidRuntime(1172):     at java.lang.reflect.Method.invoke(Method.java:511)
03-22 17:55:58.947: E/AndroidRuntime(1172):     at …
Run Code Online (Sandbox Code Playgroud)

android runtimeexception

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

在3686416字节分配的内存不足,android.view.InflateException:二进制XML文件行#1:错误膨胀类<unknown>

在调用Asynctask内部之后,仅在向父RelativeLayout添加背景图像后出现多个错误(此错误仅在使用模拟器时出现,但在与实际设备一起使用时,堆栈跟踪未显示任何内容或正常):

public class UserAuthTask extends AsyncTask<String, Void, String> {
    private boolean success = false;

    @Override
    protected String doInBackground(String... path) {
        // TODO: attempt authentication against a network service.
        try {
            // Simulate network access.
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            return null;
        }

        Log.d(Constant.TAG_AUTH, path[0]);
        String apiRequestReturn = WebServiceUtil.getRequest(path[0]);
        if (apiRequestReturn.equals("")) {
            Log.d(Constant.TAG_AUTH, "WebService request is null");
            return null;
        } else {
            Log.d(Constant.TAG_AUTH, "WebService request has data");
            return apiRequestReturn;
        }
    }

    @Override
    protected void onPostExecute(String result) {
        userAuthTask = null; …
Run Code Online (Sandbox Code Playgroud)

android out-of-memory invocationtargetexception runtimeexception inflate-exception

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

可以抛出运行时异常吗?

我写了一个类,我试图抛出一个运行时异常.代码如下

public class ExceptionTest 

{

    public static void ReadFile() throws RuntimeException, FileNotFoundException{
    try{

    BufferedReader b =new BufferedReader(new FileReader("I:\\Workspace\\Basic Java\\bin\\Exceptions\\List To Read.txt"));
    String s = b.readLine();
    while(s!=null){
        System.out.println(s);
        s=b.readLine();
    }
    }
    catch(RuntimeException e){
        throw e;
    }
    catch(FileNotFoundException e){
        throw e;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }
Run Code Online (Sandbox Code Playgroud)

而我的主要课程看起来像

public class TheMain {
public static void main(String args[]){
    ExceptionTest.ReadFile();
}
}
Run Code Online (Sandbox Code Playgroud)

我怀疑是否可以抛出运行时异常?请帮忙

java exception runtimeexception

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

JOptionPane:parentComponent没有有效的父级

我正在尝试编译此代码,但是在使用套接字编程的聊天系统中出现运行时错误,服务器成功启动,但是当我运行ClientChatApp时,

java.lang.RuntimeException : JOptionPane: parentComponent does not have a valid parent
Run Code Online (Sandbox Code Playgroud)

ChatappServer

package chatappserver;

import java.net.*;
import java.io.*;
import java.util.Vector;
import java.lang.*;

public class ChatappServer {

  private static int port = 1234;
  private static ServerSocket server = null;
  private static Socket clientSocket;
  private static String line;
  private static BufferedReader streamIn;
  private static PrintStream streamOut;


  private static Vector < String > usernames = new Vector < String > ();
  private static Vector < PrintStream > streams = new Vector < PrintStream …
Run Code Online (Sandbox Code Playgroud)

java swing runtimeexception

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

java.lang.RuntimeException: java.lang.ClassCastException: [B 不能转换为 java.lang.String

我在本地模式下运行风暴拓扑时遇到此错误。我有一个简单的程序来检查一个数是否为素数。我使用KafkaSpout作为源和风暴来处理它。Kafka 版本 2.10-0.8.2.1 风暴版本 0.9.4 zookeeper 3.4.6

下面是我检查素数的螺栓

public class PrimeNumberBolt extends BaseRichBolt 
{
    private static final long serialVersionUID = 1L;
    private OutputCollector collector;



    public void prepare( Map conf, TopologyContext context, OutputCollector collector ) 
    {
        this.collector = collector;
    }

    public void execute( Tuple tuple ) 
    {
        //System.out.println(tuple.getFields());
        //System.out.println(tuple.getString(0));
        String num = tuple.getString(0);
        //int number = tuple.getInteger( 0 );
        int number = Integer.parseInt(num);
        //System.out.println("IN Primenumber bolt = "+number);

        if( isPrime( number) )
        {  
            System.out.println( number );

        }
        collector.ack( tuple …
Run Code Online (Sandbox Code Playgroud)

java multithreading classcastexception runtimeexception apache-storm

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

Android Studio无法在Windows 10中启动:内部错误.请报告https://code.google.com/p/android/issues

我已经成功安装了Android Studio.但是当我启动它时,它开始获取SDK组件,并且在中途出现以下错误弹出java.lang.Runtime异常:IllegalArgumentException.我正在使用Windows 10操作系统.

以下是错误的完整描述

Internal error. Please report to https://code.google.com/p/android/issues

java.lang.RuntimeException: java.lang.IllegalArgumentException: Argument for @NotNull parameter 'name' of com/android/tools/idea/welcome/Platform.<init> must not be null
    at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:178)
    at com.intellij.idea.MainImpl$1$1$1.run(MainImpl.java:52)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:362)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.IllegalArgumentException: Argument for @NotNull parameter 'name' of com/android/tools/idea/welcome/Platform.<init> must not be null
    at com.android.tools.idea.welcome.Platform.<init>(Platform.java)
    at com.android.tools.idea.welcome.Platform.getLatestPlatform(Platform.java:72)
    at com.android.tools.idea.welcome.Platform.createSubtree(Platform.java:89)
    at com.android.tools.idea.welcome.InstallComponentsPath.createComponentTree(InstallComponentsPath.java:81) …
Run Code Online (Sandbox Code Playgroud)

illegalargumentexception runtimeexception android-studio windows-10

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

Java中的Throwable和Exception

假设我有一个名为BugException的类,该类从扩展而来,RuntimeException 并且BugException具有一个采用Throwable的副本构造函数。

这段代码编译和类型检查:

Throwable e = ...;
if (e instanceof BugException) {
   throw new BugException(e);
}
Run Code Online (Sandbox Code Playgroud)

为什么会这样:

Throwable e = ...;
if (e instanceof BugException) {
   throw e;
}
Run Code Online (Sandbox Code Playgroud)

不编译并给出错误消息:未处理的异常。java.lang.Throwable。?

为什么需要这种不必要的包装来满足类型检查器?

java exception throwable runtimeexception randoop

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

二进制 XML 文件第 2 行错误膨胀类 android.widget.RelativeLayout 以尝试动态实现主题

我一直在尝试在我的项目中实现动态它们,但由于某种原因它给出了以下错误。这就是我试图实现它的方式。

首先,我定义了一些自定义属性,例如:

<resources>
<attr name="themeWindowBackground" format="reference" />
<attr name="themeContentBackground" format="reference" />
<attr name="themeContentTextColor" format="reference" />
<attr name="themeContentTextColorOnPrimary" format="reference" />
<attr name="themeTextColorSuccess" format="reference" />
<attr name="themeTextColorFailure" format="reference" />
Run Code Online (Sandbox Code Playgroud)

然后我在 style.xml 文件中定义了自定义主题

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="SplashTheme" parent="AppTheme">
    <item name="android:windowBackground">@drawable/bg_splash_screen</item>
</style>

<style name="AppTheme.Black" parent="AppTheme">
    <item name="colorPrimary">@color/material_dark</item>
    <item name="colorPrimaryDark">@color/material_primary_dark</item>
    <item name="colorAccent">@color/material_accent</item>
    <item name="themeWindowBackground">@color/dark_gray</item>
    <item name="themeContentBackground">@color/dark_slate_gray</item>
    <item name="themeContentTextColor">@color/white</item>
    <item name="themeContentTextColorOnPrimary">@color/teal</item>
    <item name="themeTextColorSuccess">@color/green</item>
    <item name="themeTextColorFailure">@color/red</item>
</style> …
Run Code Online (Sandbox Code Playgroud)

android android-layout runtimeexception android-theme

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

差异 b/w 使用 i&lt;strlen() 和 str[i] != '\0'

当我使用时,for(i=0;i<strlen(s);i++)我收到时间限制超过错误。当我使用for(i=0;s[i]!='\0';i++)我的代码获得成功提交。为什么?

我还提供了来自 codechef 的问题链接 - https://www.codechef.com/problems/LCPESY

类型 1:

    for (i = 0; i < strlen(s1); i++) {
        f1[s1[i]]++;
    }
    for (i = 0; i < strlen(s2); i++) {
        f2[s2[i]]++;
    }
Run Code Online (Sandbox Code Playgroud)

类型 2:

    for (i = 0; s1[i] != '\0'; i++) {
        f1[s1[i]]++;
    }
    for (i = 0; s2[i] != '\0'; i++) {
        f2[s2[i]]++;
    }
Run Code Online (Sandbox Code Playgroud)

完整代码:

#include <stdio.h>
#include <string.h>

long int min(long int a, long int b) {
    if (a >= b) …
Run Code Online (Sandbox Code Playgroud)

c arrays string algorithm runtimeexception

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

如果操作会使对象进入非法状态,则抛出什么异常?

考虑 aProduct和 a quantity,它可以按给定的 增加和减少amount。数量绝不能变成负值,如果发生这种情况,必须禁止操作并向用户发出警告。

public class Product{
    
    private int quantity;
    
    public Product() {
        quantity = 10;
    }
    
    public void decreaseQuantity(int amount) {
        int decreasedQuantity = quantity - amount;
        if(decreasedQuantity < 0 )
            throw new RuntimeException(String.format("Decrease quantity (%s) exceeds avaiable quantity (%s)",
                    amount, quantity));
        
        quantity = decreasedQuantity;
    }
}
Run Code Online (Sandbox Code Playgroud)

例如,如果产品的数量为 10,而我尝试删除 20,则会抛出 RuntimeException。SonarCloud 建议用自定义异常替换 RuntimeException,但我想知道是否有适合这种情况的标准异常(Effective Java: Favor The Use of Standard Exceptions)。

最合适的例外似乎是IllegalStateException. 来自javadoc

表示某个方法在非法或不适当的时间被调用。换句话说,Java 环境或 Java 应用程序未处于适合所请求操作的状态。

以及来自《Effective Java》

IllegalStateException:如果调用方法时对象的状态对于该操作无效,则使用此异常。可能您有一个文件句柄,并且您在打开它之前调用了 …

java exception runtimeexception illegalstateexception

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