0

Iv'e been working with some code that will send a sms message and when i run it i get an error:

[2012-04-22 01:01:00 - SMS_Experiment] Dx 1 error; aborting [2012-04-22 01:01:00 - SMS_Experiment] Conversion to Dalvik format failed with error 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();
            }
        }
      });
       }
       }

and the main.xml looks like:

    <?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>

any help would be greatly appreciated!

enter image description here

enter image description here

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 上查看此线程“ Conversion to Dalvik format failed with error 1 ”

此处的更多信息:转换为 dalvik 格式的原因失败,错误 1

于 2012-04-22T05:16:44.117 回答