0

私はSMSメッセージを送信するいくつかのコードで作業していて、それを実行するとエラーが発生します:

[2012-04-22 01:01:00-SM​​S_Experiment]Dx1エラー。中止[2012-04-2201:01:00-SM​​S_Experiment]Dalvik形式への変換がエラー1で失敗しました

   import android.app.Activity;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.view.View;
   import android.view.View.OnClickListener;
   import android.widget.Button;
   import android.widget.Toast;

   public class SMS_ExperimentActivity extends Activity {

Button buttonSend;

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        buttonSend = (Button) findViewById(R.id.buttonSend);
       final String phoneNumber="**********";
       buttonSend.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
               try {
                 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"+ phoneNumber + "?body=Hello%20WORLD" )));

            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                    "SMS faild, please try again later!",
                    Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
      });
       }
       }

main.xmlは次のようになります。

    <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/buttonSend"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Send" />

  </LinearLayout>

どんな助けでも大歓迎です!

ここに画像の説明を入力してください

ここに画像の説明を入力してください

4

2 に答える 2

0

変更したコードを試してください:::

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;


public class SMS_ExperimentActivity extends Activity {
    @overide
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nameoflayout);
        buttonSend = (Button) findViewById(R.id.buttonSend);
       final String phoneNumber="**********";
       buttonSend.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
               try {
                 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"+ phoneNumber)));

            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                    "SMS faild, please try again later!",
                    Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
      });
       }
       }
于 2012-04-22T06:04:33.530 に答える
0

外部Jarのこのスレッド「 Dalvik形式への変換がエラー1で失敗しました」を参照してください。

詳細はこちら:dalvik形式への変換の理由がエラー1で失敗しました

于 2012-04-22T05:16:44.117 に答える