Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不知道如何理解logcat告诉我的是错的_Java_Android_Xml_Android Edittext_Logcat - Fatal编程技术网

Java 不知道如何理解logcat告诉我的是错的

Java 不知道如何理解logcat告诉我的是错的,java,android,xml,android-edittext,logcat,Java,Android,Xml,Android Edittext,Logcat,这是我的logcat给我的错误。我知道这和我的编辑文本有关,但我不确定是什么。我希望这是一个愚蠢的错误,可以很快很容易地解决,这样我就可以尽快继续工作。如果你能帮助我,请帮帮我,谢谢 该错误仅在程序运行时发生 02-25 16:30:19.417: E/AndroidRuntime(15259): FATAL EXCEPTION: main 02-25 16:30:19.417: E/AndroidRuntime(15259): java.lang.RuntimeException: U

这是我的logcat给我的错误。我知道这和我的编辑文本有关,但我不确定是什么。我希望这是一个愚蠢的错误,可以很快很容易地解决,这样我就可以尽快继续工作。如果你能帮助我,请帮帮我,谢谢

该错误仅在程序运行时发生

02-25 16:30:19.417: E/AndroidRuntime(15259): FATAL EXCEPTION: main
    02-25 16:30:19.417: E/AndroidRuntime(15259): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Wicker/com.Wicker.InviteSMS}: java.lang.ClassCastException: android.widget.EditText
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at android.app.ActivityThread.access$1500(ActivityThread.java:132)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at android.os.Handler.dispatchMessage(Handler.java:99)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at android.os.Looper.loop(Looper.java:143)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at android.app.ActivityThread.main(ActivityThread.java:4196)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at java.lang.reflect.Method.invokeNative(Native Method)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at java.lang.reflect.Method.invoke(Method.java:507)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at dalvik.system.NativeStart.main(Native Method)
    02-25 16:30:19.417: E/AndroidRuntime(15259): Caused by: java.lang.ClassCastException: android.widget.EditText
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at com.Wicker.InviteSMS.onCreate(InviteSMS.java:48)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
    02-25 16:30:19.417: E/AndroidRuntime(15259):    ... 11 more
这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/contacts"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:gravity="center"
                android:paddingBottom="10dp"
                android:paddingLeft="10dp"
                android:paddingTop="10dp"
                android:text="@string/contacts"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#fff" /> <!-- android:background="@drawable/header" for header background -->

            <Button
                android:id="@+id/contactsButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:text="@string/contacts" />
        </RelativeLayout>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/enter_contact"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <AutoCompleteTextView
            android:id="@+id/contactnumber"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/to" >

            <requestFocus />
        </AutoCompleteTextView>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/message_to_send"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/invite_text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/message_join" />

        <Button
            android:id="@+id/sendtxt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:onClick="doLaunchContactPicker"
            android:text="@string/send_txt" />
    </LinearLayout>

</ScrollView>

这是运行它的类

public class InviteSMS extends Activity {

    private static final int CONTACT_PICKER_RESULT = 1001;
    private static final String DEBUG_TAG = null;

    private SimpleAdapter mAdapter;

    Button btnSendSMS;
    AutoCompleteTextView txtPhoneNo;
    Button Attachment;
    Button contactsbutton;
    Button gallery;
    EditText txtMessage;

    Context context = this;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.invite_text);

        btnSendSMS = (Button) findViewById(R.id.sendtxt);
        txtPhoneNo = (AutoCompleteTextView) findViewById(R.id.contactnumber);
        txtMessage = (EditText) findViewById(R.id.invite_text);
        contactsbutton = (Button) findViewById(R.id.contactsButton);

        txtPhoneNo.setAdapter(mAdapter);

        btnSendSMS.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String phoneNo = txtPhoneNo.getText().toString();
                String message = txtMessage.getText().toString();

                if (phoneNo.length() > 0 && message.length() > 0)
                    sendSMS(phoneNo, message);
                else
                    Toast.makeText(getBaseContext(),
                            "Please enter both phone number and message.",
                            Toast.LENGTH_SHORT).show();
            }

        });
        contactsbutton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

                Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
                        Contacts.CONTENT_URI);
                startActivityForResult(contactPickerIntent,
                        CONTACT_PICKER_RESULT);

            }
        });
    }

    private void sendSMS(String phoneNumber, String message) {
        PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this,
                InviteSMS.class), 0);

        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
                SENT), 0);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
                new Intent(DELIVERED), 0);
        registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode()) {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS sent",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    Toast.makeText(getBaseContext(), "Generic failure",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(getBaseContext(), "No service",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(getBaseContext(), "Null PDU",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(getBaseContext(), "Radio off",
                            Toast.LENGTH_SHORT).show();
                    break;
                }
            }
        }, new IntentFilter(SENT));

        // ---when the SMS has been delivered---
        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode()) {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS delivered",
                            Toast.LENGTH_SHORT).show();
                    break;
                case Activity.RESULT_CANCELED:
                    Toast.makeText(getBaseContext(), "SMS not delivered",
                            Toast.LENGTH_SHORT).show();
                    break;
                }
            }
        }, new IntentFilter(DELIVERED));

        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
            case CONTACT_PICKER_RESULT:
                Cursor cursor = null;
                String phone = "";
                try {
                    Bundle extras = data.getExtras();
                    Set<String> keys = extras.keySet();
                    Iterator<String> iterate = keys.iterator();
                    while (iterate.hasNext()) {
                        String key = iterate.next();
                        Log.v(DEBUG_TAG, key + "[" + extras.get(key) + "]");
                    }

                    Uri result = data.getData();
                    Log.v(DEBUG_TAG,
                            "Got a contact result: " + result.toString());

                    // get the contact id from the Uri
                    String id = result.getLastPathSegment();

                    cursor = getContentResolver().query(Phone.CONTENT_URI,
                            null, Phone.CONTACT_ID + "=?", new String[] { id },
                            null);

                    int phoneIdx = cursor.getColumnIndex(Phone.DATA);

                    if (cursor.moveToFirst()) {

                        phone = cursor.getString(phoneIdx);

                        Log.v(DEBUG_TAG, "Got Contact: " + phone);

                    } else {
                        Log.w(DEBUG_TAG, "No results");
                    }
                } catch (Exception e) {
                    Log.e(DEBUG_TAG, "Failed to get phone data", e);
                } finally {
                    if (cursor != null) {
                        cursor.close();
                    }
                    EditText phoneEntry = (EditText) findViewById(R.id.invite_text);
                    phoneEntry.setText(phone);
                    if (phone.length() == 0) {
                        Toast.makeText(this,
                                "No Phone Number found for contact.",
                                Toast.LENGTH_LONG).show();
                    }

                }

                break;
            }

        } else {
            Log.w(DEBUG_TAG, "Warning: activity result not ok");
        }
    }

}
public class InviteSMS扩展活动{
专用静态最终int触点\u选择器\u结果=1001;
私有静态最终字符串DEBUG_TAG=null;
私人simpledapter mAdapter;
按钮btnSendSMS;
自动完成文本视图txtPhoneNo;
按钮附件;
按钮触点按钮;
按钮库;
编辑文本txtMessage;
上下文=这个;
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.invite_text);
btnSendSMS=(按钮)findViewById(R.id.sendtxt);
txtPhoneNo=(AutoCompleteTextView)findViewById(R.id.contactnumber);
txtMessage=(EditText)findViewById(R.id.invite_text);
contactsbutton=(按钮)findViewById(R.id.contactsbutton);
txtPhoneNo.setAdapter(mAdapter);
btnSendSMS.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
字符串phoneNo=txtPhoneNo.getText().toString();
String message=txtMessage.getText().toString();
if(phoneNo.length()>0&&message.length()>0)
发送短信(电话号码、短信);
其他的
Toast.makeText(getBaseContext(),
“请同时输入电话号码和信息。”,
吐司。长度(短)。show();
}
});
contactsbutton.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图){
Intent contactPickerIntent=新的Intent(Intent.ACTION\u PICK,
联系人。内容(URI);
startActivityForResult(contactPickerIntent,
联系_选择器_结果);
}
});
}
专用void发送短信(字符串电话号码、字符串消息){
PendingEvent pi=PendingEvent.getActivity(此,0,新意图(此,
0);
String SENT=“SMS_SENT”;
String DELIVERED=“SMS_DELIVERED”;
PendingEvent sentPI=PendingEvent.getBroadcast(此,0,新意图(
已发送),0);
PendingEvent deliveredPI=PendingEvent.getBroadcast(此,0,
新意向(已交付),0);
registerReceiver(新广播接收器(){
@凌驾
公共void onReceive(上下文arg0,意图arg1){
开关(getResultCode()){
案例活动。结果\u正常:
Toast.makeText(getBaseContext(),“SMS已发送”,
吐司。长度(短)。show();
打破
案例smsmsmanager.RESULT\u错误\u一般\u失败:
Toast.makeText(getBaseContext(),“通用失败”,
吐司。长度(短)。show();
打破
案例smsmsmanager.RESULT\u错误\u否\u服务:
Toast.makeText(getBaseContext(),“无服务”,
吐司。长度(短)。show();
打破
案例smsmsmanager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(),“空PDU”,
吐司。长度(短)。show();
打破
案例smsmsmanager.RESULT\u ERROR\u RADIO\u OFF:
Toast.makeText(getBaseContext(),“无线电关闭”,
吐司。长度(短)。show();
打破
}
}
},新意向过滤器(已发送));
//---短信发送后---
registerReceiver(新广播接收器(){
@凌驾
公共void onReceive(上下文arg0,意图arg1){
开关(getResultCode()){
案例活动。结果\u正常:
Toast.makeText(getBaseContext(),“SMS传递”,
吐司。长度(短)。show();
打破
案例活动.RESULT\u已取消:
Toast.makeText(getBaseContext(),“短信未送达”,
吐司。长度(短)。show();
打破
}
}
},新IntentFilter(已交付);
SmsManager sms=SmsManager.getDefault();
sendTextMessage(电话号码、空、消息、sentPI、deliveredPI);
}
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
if(resultCode==RESULT\u OK){
开关(请求代码){
案例联系人\u选取者\u结果:
游标=空;
字符串phone=“”;
试一试{
Bundle extras=data.getExtras();
Set keys=extras.keySet();
Iterator iterate=keys.Iterator();
while(iterate.hasNext()){
字符串键=iterate.next();
Log.v(DEBUG_标记,key++“[”+extras.get(key)+“]);
}
Uri结果=data.getData();
Log.v(调试标签,
获取了一个联系结果:“+result.toString());
//从Uri获取联系人id
字符串id=result.getLastPathSegment();
cursor=getContentResolver().query(Phone.CONTENT\u URI,
N
txtMessage = (EditText) findViewById(R.id.invite_text);
    <EditText
        android:id="@+id/invite_text"
        android:layout_width="fill_parent"
        ...
        " />