启动基于聊天的活动时ClassNotFoundException

时间:2017-10-23 16:33:37

标签: java android

重新发布此内容,因为我在上一篇文章中使用了错误的标题,但并未在任何地方结束。

这个聊天窗口项目出现问题时,只有在调用ChatWindow活动时才会崩溃。

在单击服务器场的调试器中,我在窗口中看到此消息:

@FastNative
static native Class<?> classForName(String className, boolean shouldInitialize,
        ClassLoader classLoader) throws ClassNotFoundException;

我还在“变量”窗口中看到以下消息:

Exception = {ClassNotFoundException@3804}

以下是ChatWindow代码(不断崩溃的活动):

public class ChatWindow extends AppCompatActivity {

    ListView myDisplay;
    EditText myChat;
    Button mySend;
    ArrayList<String> myList;
    ChatAdapter messageAdapter;


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



        //declarations
        myDisplay = (ListView) findViewById(R.id.display);
        myChat = (EditText) findViewById(R.id.chat);
        mySend = (Button) findViewById(R.id.sndBtn);
        myList = new ArrayList<>();
        //in this case, “this” is the ChatWindow, which is-A Context object
        messageAdapter =new ChatAdapter( this );
        myDisplay.setAdapter (messageAdapter);


        //send button actions
        mySend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String message;
                message = myChat.getText().toString();
                myList.add(message);
                messageAdapter.notifyDataSetChanged(); //this restarts the process of getCount()/getView()
                myChat.setText("");

            }
        });

    }
    private class ChatAdapter extends ArrayAdapter<String> {
            public ChatAdapter(Context ctx) {
            super(ctx, 0);
        }
        @Override
        public int getCount() {
            return myList.size();
        }
        @Override
        public String getItem(int position) {
            return myList.get(position);
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
           LayoutInflater inflater = ChatWindow.this.getLayoutInflater();
            View result = null ;
            if(position%2 == 0)
                result = inflater.inflate(R.layout.chat_row_incoming, null);
            else
                result = inflater.inflate(R.layout.chat_row_outgoing, null);

            TextView message = (TextView)result.findViewById(R.id.message_text);
            message.setText(   getItem(position)  ); // get the string at position
            return result;


        }
    }



}

1 个答案:

答案 0 :(得分:0)

编辑配置中选择应用并运行您的代码,我通过这种方式解决了同样的问题。 see picture