2012-02-06 42 views
0

我是一個全新的傢伙在這裏,我不知道它是否正確的地方問我愚蠢的懷疑...但請幫助我的傢伙...我編碼一個簡單的短信發送程序和它顯示運行時errror..i不KNW如何調試it..plz幫助Android短信發送應用程序運行時錯誤

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> 

我的例外是目錄下載

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

你好,你怎麼解決這個問題? – 2013-10-22 05:37:15

回答

0

請發佈運行時exception from logcat。很難說沒有這一點,但我的猜測是,你有沒有要求相應的權限,你可以添加以下到您的清單XML文件的頂級manifest節點:

<uses-permission android:name="android.permission.SEND_SMS" /> 
+0

謝謝... Bu我已經添加了權限。我的logcat是 – 2012-02-06 17:03:31

+0

您的logcat是...? – 2012-02-06 17:07:53

+0

其現在編輯的問題..請幫助@Sam_D – 2012-02-06 17:10:47