简单的android活动发送短信错误“转换为Dalvik格式失败,错误1”

时间:2012-04-22 05:06:27

标签: android sms

我一直在使用一些会发送短信的代码,当我运行它时会出现错误:

[2012-04-22 01:01:00 - SMS_Experiment] Dx 1错误;中止 [2012-04-22 01:01:00 - SMS_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>

任何帮助将不胜感激!

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

请在外部Jar上查看此主题“Conversion to Dalvik format failed with error 1

此处提供更多信息:Conversion to dalvik format failed with error 1

的原因

答案 1 :(得分: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();
            }
        }
      });
       }
       }