1

私のアプリケーションは、ページの返信 (sms の送信) を持っています....しかし、私はメッセージを送信できません....誰も私にコードを助けてくれます...私のコードにエラーがあると思います....どうすればよいですか私はそのエラーを削除します...

Reply.java

public class Reply extends Activity {

EditText replyText;
Button reply;
String replyString,name,phoneNo, message,nickname,body;
SQLiteDatabase messagedb,mydb;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reply);

    replyText=(EditText)findViewById(R.id.editTextReply);
    reply=(Button)findViewById(R.id.buttonReply);

    Bundle c = getIntent().getExtras();

    name= c.getString("nick");
    message=c.getString("body");

    System.out.println("nickname in reply : "+name);

    messagedb=this.openOrCreateDatabase("message",0, null);
    messagedb.execSQL(
            "CREATE TABLE IF NOT EXISTS tab2( nickname varchar,sender INT(13),body varchar)");

    Cursor  cur1=messagedb.rawQuery("select * from tab2 where nickname='"+name+"'", null);

    while(cur1.moveToNext())
    {
        phoneNo=cur1.getString(cur1.getColumnIndex("sender"));
        System.out.println("Number in cur1 : "+phoneNo);
    }

    TextView tv = (TextView)findViewById(R.id.textView2);  
    tv.setText(nickname);

    reply.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

            message=replyText.getText().toString();

            sendSMS(phoneNo, message); 


        }


    });


}

private void sendSMS(String phoneNumber, String message)
{        
    PendingIntent pi = PendingIntent.getActivity(this, 0,
        new Intent(this, MessageViewPage.class), 0);                
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, pi, null);        
}    



}

返信.xml

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

<EditText
    android:id="@+id/editTextReply"
    android:layout_width="fill_parent"
    android:layout_height="300dp" 
    android:background="@drawable/reply_edit"
    android:paddingLeft="21dp"
    android:paddingRight="14dp"
    android:paddingTop="37dp"
    android:paddingBottom="37dp"
    android:layout_alignParentTop="true"
    android:layout_marginTop="50dp">
</EditText>

<Button
    android:id="@+id/buttonReply"
    android:layout_width="100dp"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="50dp"
    android:layout_centerHorizontal="true"
    android:background="@drawable/white_bn"
    android:layout_marginTop="35dp"
    android:text="Reply" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="10dp"
    android:layout_alignParentTop="true"
    android:layout_marginTop="14dp"
    android:text="To : "
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignParentTop="true"
    android:layout_marginTop="17dp"
    android:layout_marginLeft="50dp"
    android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

そして私も許可を使用します

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



    07-06 22:42:35.515: W/dalvikvm(834): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
    07-06 22:42:35.554: E/AndroidRuntime(834): FATAL EXCEPTION: main
    07-06 22:42:35.554: E/AndroidRuntime(834): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dpn.pack/com.dpn.pack.MessageViewPage}: java.lang.NullPointerException
    07-06 22:42:35.554: E/AndroidRuntime(834):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    07-06 22:42:35.554: E/AndroidRuntime(834):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    07-06 22:42:35.554: E/AndroidRuntime(834):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    07-06 22:42:35.554: E/AndroidRuntime(834):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    07-06 22:42:35.554: E/AndroidRuntime(834):  at android.os.Handler.dispatchMessage(Handler.java:99)
    07-06 22:42:35.554: E/AndroidRuntime(834):  at android.os.Looper.loop(Looper.java:123)
    07-06 22:42:35.554: E/AndroidRuntime(834):  at android.app.ActivityThread.main(ActivityThread.java:4627)
   07-06 22:42:35.554: E/AndroidRuntime(834):   at java.lang.reflect.Method.invokeNative(Native Method)
    07-06 22:42:35.554: E/AndroidRuntime(834):  at java.lang.reflect.Method.invoke(Method.java:521)
    07-06 22:42:35.554: E/AndroidRuntime(834):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    07-06 22:42:35.554: E/AndroidRuntime(834):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    07-06 22:42:35.554: E/AndroidRuntime(834):  at dalvik.system.NativeStart.main(Native Method)
    07-06 22:42:35.554: E/AndroidRuntime(834): Caused by: java.lang.NullPointerException
    07-06 22:42:35.554: E/AndroidRuntime(834):  at com.dpn.pack.MessageViewPage.onCreate(MessageViewPage.java:30)
   07-06 22:42:35.554: E/AndroidRuntime(834):   at      android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
   07-06 22:42:35.554: E/AndroidRuntime(834):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
   07-06 22:42:35.554: E/AndroidRuntime(834):   ... 11 more
4

1 に答える 1

0

MessageViewPage.java の 30 行目の NullPointerException を修正します。

sendSms() 行に到達する前に問題が発生していると思います

于 2012-07-08T03:00:32.880 に答える