当前位置: 首页 > 知识库问答 >
问题:

无法在AndroidStudio中实例化活动组件信息

沈琛
2023-03-14

我目前正在一个android项目,当试图运行后构建的应用程序平原崩溃。以下是LogCat详细信息:

2021-11-13 13:37:08.105 11908-11908/com.example.finalprojectE/AndroidRuntime: FATAL EXCEPTION:主进程:com.example.finalproject, PID: 11908java.lang.RuntimeExc0019:无法实例化活动ComponentInfo{com.example.finalproject/com.example.finalproject.MainActivity}:java.lang.################################################################################################################################################################################################lib/arm64, /system/lib64, /system/system_ext/lib64]]在android.app.ActivityThread.perform启动活动(ActivityThread.java:3492)在android.app.ActivityThread.handle启动活动(ActivityThread.java:3748)在android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)在android.app.servertransaction.TransactionExecutor.execute回调(TransactionExecutor. java: 135)在android. app. servertransaction.在android. app上执行(TransactionExecutor. java: 95)。ActivityThread$H. handleMessage(ActivityThread. java: 2187)at android. os.在android. os.在android. app.ActivityThread. main(ActivityThread. java: 8057)在java. lang.反射。方法调用(本机方法)在com. android. interal. os。RuntimeInit$method odAndArgsCaller. run(RuntimeInit. java: 620)在com. android. interal. os。ZygoteInit. main(ZygoteInit. java: 1011)引起:java. lang.没有找到类"com. list. finalproject.在路径上的主要活动:DexPathList[[[zip file"/data/app/~~jkeaLklNJ36aGEn6TYoiKg==/com. ex. finalproject-gztqZ1eOAQvQH4Dc0_rPwA==/base. apk],nativeLibraryDirectory=[/data/app/~~jkeaLklNJ36aGEn6TYoiKg==/com. ex. finalproject-gztqZ1eOAQvQH4Dc0_rPwA==/lib/arm64, /system/lib64, /system/system_ext/lib64]]在dalvik. system。在java. lang的BaseDexClassLoader. findClass(BaseDexClassLoader. java: 207)。ClassLoader. loadClass(ClassLoader. java: 379)在java. lang.ClassLoader. loadClass(ClassLoader. java: 312)在android. app.在androidx. core. app上的AppComponentFactory. instantiateActive(AppComponentFactory. java: 95)。在android. app.在android. app.在android. app上的ActivityThread. performLaunch活动(ActivityThread. java: 3480)。处理启动活动(ActivityThread. java: 3748)

代码如下:main活动。JAVA

    package com.example.finalproject;

import android.os.Bundle;
import android.view.View;
import android.widget.AbsSpinner;
import android.widget.EditText;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.scaledrone.lib.Listener;
import com.scaledrone.lib.Member;
import com.scaledrone.lib.Room;
import com.scaledrone.lib.RoomListener;
import com.scaledrone.lib.Scaledrone;

import java.util.Random;

public class MainActivity extends AppCompatActivity implements RoomListener {

    private String channelID = "BmQHPGgq5n0DImdL";
    private String roomName = "observable-room";
    private EditText editText;
    private Scaledrone scaledrone;
    private MessageAdapter messageAdapter;
    private ListView messagesView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editText = (EditText) findViewById(R.id.editText);

        messageAdapter = new MessageAdapter(this);
        messagesView = (ListView) findViewById(R.id.messages_view);
        messagesView.setAdapter(messageAdapter);

        MemberData data = new MemberData(getRandomName(), getRandomColor());

        scaledrone = new Scaledrone(channelID, data);
        scaledrone.connect(new Listener() {
            @Override
            public void onOpen() {
                System.out.println("Scaledrone connection open");
                scaledrone.subscribe(roomName, MainActivity.this);
            }

            @Override
            public void onOpenFailure(Exception ex) {
                System.err.println(ex);
            }

            @Override
            public void onFailure(Exception ex) {
                System.err.println(ex);
            }

            @Override
            public void onClosed(String reason) {
                System.err.println(reason);
            }
        });
    }

    public void sendMessage(View view) {
        String message = editText.getText().toString();
        if (message.length() > 0) {
            scaledrone.publish(roomName, message);
            editText.getText().clear();
        }
    }

    @Override
    public void onOpen(Room room) {
        System.out.println("Connected to room");
    }

    @Override
    public void onOpenFailure(Room room, Exception ex) {
        System.err.println(ex);
    }

    @Override
    public void onMessage(Room room, com.scaledrone.lib.Message receivedMessage) {
        final ObjectMapper mapper = new ObjectMapper();
        try {
            final MemberData data = mapper.treeToValue(receivedMessage.getMember().getClientData(), MemberData.class);
            boolean belongsToCurrentUser = receivedMessage.getClientID().equals(scaledrone.getClientID());
            final Message message = new Message(receivedMessage.getData().asText(), data, belongsToCurrentUser);
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    messageAdapter.add(message);
                    messagesView.setSelection(messagesView.getCount() - 1);
                }
            });
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

    private String getRandomName() {
        String[] adjs = {"autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark", "summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter", "patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue", "billowing", "broken", "cold", "damp", "falling", "frosty", "green", "long", "late", "lingering", "bold", "little", "morning", "muddy", "old", "red", "rough", "still", "small", "sparkling", "throbbing", "shy", "wandering", "withered", "wild", "black", "young", "holy", "solitary", "fragrant", "aged", "snowy", "proud", "floral", "restless", "divine", "polished", "ancient", "purple", "lively", "nameless"};
        String[] nouns = {"waterfall", "river", "breeze", "moon", "rain", "wind", "sea", "morning", "snow", "lake", "sunset", "pine", "shadow", "leaf", "dawn", "glitter", "forest", "hill", "cloud", "meadow", "sun", "glade", "bird", "brook", "butterfly", "bush", "dew", "dust", "field", "fire", "flower", "firefly", "feather", "grass", "haze", "mountain", "night", "pond", "darkness", "snowflake", "silence", "sound", "sky", "shape", "surf", "thunder", "violet", "water", "wildflower", "wave", "water", "resonance", "sun", "wood", "dream", "cherry", "tree", "fog", "frost", "voice", "paper", "frog", "smoke", "star"};
        return (
                adjs[(int) Math.floor(Math.random() * adjs.length)] +
                        "_" +
                        nouns[(int) Math.floor(Math.random() * nouns.length)]
        );
    }

    private String getRandomColor() {
        Random r = new Random();
        StringBuffer sb = new StringBuffer("#");
        while(sb.length() < 7){
            sb.append(Integer.toHexString(r.nextInt()));
        }
        return sb.toString().substring(0, 7);
    }
}

主要活动。xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:clipToPadding="false"
    android:focusableInTouchMode="true"
    tools:context=".MainActivity">

    <ListView
        android:layout_width="match_parent"
        android:id="@+id/messages_view"
        android:layout_weight="2"
        android:divider="#fff"
        android:layout_height="wrap_content"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:ems="10"
            android:hint="Write a message"
            android:inputType="text"
            android:paddingHorizontal="10dp"
            android:text="" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:scaleType="fitCenter"
            android:padding="20dp"
            android:layout_marginHorizontal="10dp"
            android:background="@drawable/ic_send_black_24dp"
            android:onClick="sendMessage"/>

    </LinearLayout>

</LinearLayout>

AndroidManifest。xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.finalproject">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Finalproject">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我确实研究了其他关于同一个问题的线索,但仍然无法破解。

谢啦

共有1个答案

彭展
2023-03-14

检查RoomListener库是否正确添加到Gradle。堆栈痕迹似乎是从那里开始的。

 类似资料:
  • 很好的一天!我正在努力解决这个问题一周,这是以前没有的(也就是说,这个程序以前是有效的)。 问题:我的登录表单的GUI将不再加载。 给定:(LoginScreen类视图) 我的login_screenxml代码: 最后,我的AndroidID清单。xml 这是我的Logcat输出: 注意:每当我在“扩展活动”之后删除代码“implements JPacketListener”,并删除它的方法(on

  • 我的应用程序运行得很好,我可以从一个活动转到另一个活动,然后我添加了一些Toast消息用于注册按钮,然后我在尝试从MainActivity转到RegistrationActivity时遇到了这个错误。。 美娜ctivity.kt 注册ctivity.kt activity_main.xml 活动注册。xml 显示 和logchat 2019-12-09 09:08:16.171 28691-286

  • 我有一段时间在写代码 我的错误是: 无法实例化活动组件信息{com.example.example/com.example.sample.MainActivity}:java。lang.NullPointerException:尝试调用虚拟方法“android”。所容纳之物下午。Android应用信息。所容纳之物上下文对空对象引用执行getApplicationInfo()

  • 我是Android程序员的新手。最近,我尝试在android应用程序中使用google map v2制作项目,但是我得到了很多错误(我已经将google play服务添加到我的库中,并且在这里找到了类似的主题,但是没有解决我的问题)。请看我的日志猫吼: my mainactivity.java: 我在这里使用的是fragment,所以这里是fragment_main.xml: 还有我的舱单 这里是

  • 我有一个浮动按钮在一个片段,并希望传递意图到另一个活动。但是,当我按下浮动按钮时,导致“无法启动activity ComponentInfo”错误。 ------------编辑---------------------- 下面是我的意图代码:

  • 问题内容: 在将运行良好的应用程序转换为库(包括其Activity类!)之后,我试图通过简单地超类库的活动来创建使用整个库的应用程序: Eclipse构建了这个新的“重新架构化”的应用程序,没有任何错误,但是当我尝试运行它时,出现了一个异常: 我不知道为什么会这样,因为当类恰好是构建的派生类(没有错误!)并且现在尝试运行时,由于“未找到类”的错误。 我该如何解决? 我想念什么? 编辑 (通过@Ca