Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
简单android活动发送短信错误“转换为Dalvik格式失败,错误1”_Android_Sms - Fatal编程技术网

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

简单android活动发送短信错误“转换为Dalvik格式失败,错误1”,android,sms,Android,Sms,我一直在使用一些可以发送短信的代码,当我运行它时,我发现一个错误: [2012-04-22 01:01:00-SMS_实验]Dx 1错误;流产 [2012-04-22 01:01:00-SMS_实验]转换为Dalvik格式失败,错误为1 import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import and

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

[2012-04-22 01:01:00-SMS_实验]Dx 1错误;流产 [2012-04-22 01:01:00-SMS_实验]转换为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>
任何帮助都将不胜感激

请在外部Jar上查看此线程


此处的详细信息:原因

请尝试修改后的代码:

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();
            }
        }
      });
       }
       }

在Manifeat文件中添加了权限?我添加了android.permission.SEND_SMS权限…还有其他我应该添加的权限吗?一旦关闭模拟器并重新打开它,也会清理您的项目。是否希望我发布清单文件?好的,我将关闭模拟器并重新打开。请不要每次更改内容时都添加新的答案。编辑您的原始答案以添加/更新新信息。您是否有任何外部jar addedGo到Project»Properties»Java Build Path»库中,并删除除Android X.Y(在我的例子中是Android 1.5)之外的所有jar addedGo。单击“确定”。转到项目»清理»清理下面选择的项目»选择您的项目并单击确定。这应该行得通。我的库中有三个列表…..1.android.jar-Users/codenamejpiterx/android-sdks/platfroms//android-10…..2.android 4.0.3…..3.com.android.ide.eclipse.ide.Libraries…..我应该去掉哪两个?你能分享它的屏幕截图吗