新的二进制XML文件行#19:错误导致类活动

时间:2016-08-21 01:28:38

标签: java android xml android-studio

这是我正在研究的信使应用程序。我环顾四周,找不到同一品牌的问题。我禁用并重新启用了Messenger应用程序,从那以后它就无法运行了。请帮忙! 创建部分的一部分

package com.danny4help.gchat;

import android.content.Intent;
import android.inputmethodservice.ExtractEditText;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class GChatCreateActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gchat_create);
    }
    public void send(View view){
        ExtractEditText eet = (ExtractEditText) findViewById(R.id.eet);
        String message = eet.getText().toString();
        Intent intent = new Intent(this, GChatReceiveActivity.class);
        intent.putExtra(GChatReceiveActivity.EXTRA_MESSAGE,message);
        String title = getString(R.string.chooser);
     //   Intent chosenIntent = Intent.createChooser(intent,title);
            startActivity(intent);

        }
    }

接收部分的一部分

 package com.danny4help.aolcreate;

    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.TextView;

    public class AOLReceive extends AppCompatActivity {
    public static final String EXTRA_MESSAGE = "message";
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_aolreceive);

            Intent intent = getIntent();
            String messageSent = intent.getStringExtra(EXTRA_MESSAGE);
            TextView messageView = (TextView) findViewById(R.id.message);
            messageView.setText(messageSent);
        }
    }

创建xml                      

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/send"
    android:id="@+id/send"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:onClick="sendMessage"/>

<android.inputmethodservice.ExtractEditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/eet"
    android:layout_above="@+id/send"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="75dp"
        android:ems="10"/>

    <activity android:name="SendActivity">
        <intent-filter>
            <action android:name="android.intent.action.SEND"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="text/plain"/>
            <data android:mimeType="image/*"/>

         </intent-filter>
    </activity>
</RelativeLayout>

收到xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
     android:paddingTop="@dimen/activity_vertical_margin"
     tools:context="com.danny4help.aolcreate.AOLReceive">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/message"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
 </RelativeLayout>

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

我发现错误是在Button内你定义onClick方法名称是sendMessage而在java代码中你是创建方法send,这是不一样的为sendMessage。所以将你的java代码更改为以下方式。

public void sendMessage(View view){
        ExtractEditText eet = (ExtractEditText) findViewById(R.id.eet);
        String message = eet.getText().toString();
        Intent intent = new Intent(this, GChatReceiveActivity.class);
        intent.putExtra(GChatReceiveActivity.EXTRA_MESSAGE,message);
        String title = getString(R.string.chooser);
     //   Intent chosenIntent = Intent.createChooser(intent,title);
            startActivity(intent);

    }

简而言之:

您必须在xml中声明方法更改方法名称。