我是一个全新的人在这里,我不知道它是否适合问我愚蠢的怀疑...但请帮助我们...我编写了一个简单的短信发送programe和它显示运行时错误..我不知道如何调试它..plz help
package com.smsProject;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class SmsProjectActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buttonSend=(Button)findViewById(R.id.send);
buttonSend.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String msg=editTextmessage.getText().toString();
String num=editTextnumber.getText().toString();
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(num,null, msg,null,null);
editTextmessage.setText("");
editTextnumber.setText("");
}
}
我的main.xml文件是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="@drawable/jibin">
<EditText
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Enter the message">
<requestFocus />
</EditText>
<EditText
android:id="@+id/num"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|textPersonName" android:hint="Enter a number"/>
<Button
android:id="@+id/send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
我的异常catlog是
01-31 20:40:43.587: W/dalvikvm(1593): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-31 20:40:43.607: E/AndroidRuntime(1593): FATAL EXCEPTION: main
01-31 20:40:43.607: E/AndroidRuntime(1593): java.lang.NullPointerException
01-31 20:40:47.936: W/InputManagerService(71): Got RemoteException sending setActive(false) notification to pid 1593 uid 10038
01-31 20:43:45.129: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 20:48:45.130: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 20:49:43.546: W/dalvikvm(1638): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-31 20:49:43.556: E/AndroidRuntime(1638): FATAL EXCEPTION: main
01-31 20:49:43.556: E/AndroidRuntime(1638): java.lang.NullPointerException
01-31 20:49:47.227: W/InputManagerService(71): Got RemoteException sending setActive(false) notification to pid 1638 uid 10038
01-31 20:53:45.137: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 20:58:45.151: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:03:45.156: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:08:45.167: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:13:45.177: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:18:45.178: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:23:45.187: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:28:45.187: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:33:45.196: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:38:45.199: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:43:45.207: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:48:45.211: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
01-31 21:52:31.657: W/dalvikvm(1758): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-31 21:52:31.667: E/AndroidRuntime(1758): FATAL EXCEPTION: main
01-31 21:52:31.667: E/AndroidRuntime(1758): java.lang.NullPointerException
01-31 21:53:45.216: D/SntpClient(71): request time failed: java.net.SocketException: Address family not supported by protocol
答案 0 :(得分:1)
请发布运行时exception from logcat。很难说没有它,但我的猜测是你没有请求适当的权限,尝试将它添加到清单xml文件的顶级manifest
节点:
<uses-permission android:name="android.permission.SEND_SMS" />