有一个代码:
MainActivity.java:
package asus.example.com.notes1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ShareActionProvider;
public class MainActivity extends Activity {
private ShareActionProvider shareActionProvider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.menu_main,menu);
MenuItem menuItem = menu.findItem(R.id.action_share);
shareActionProvider = (ShareActionProvider) menuItem.getActionProvider();
setIntent("This is example test");
return true;
}
private void setIntent(String text) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, text);
shareActionProvider.setShareIntent(intent);
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.action_create_order:
Intent intent = new Intent(this, OrderActivity.class);
startActivity(intent);
return true;
case R.id.action_settings:
return true;
default:
return true;
}
}
}
运行程序时,出现错误:
org.gradle.api.tasks.TaskExecutionException:任务执行失败 ':app:transformClassesWithInstantRunForDebug'。在 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java: 造成原因:com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:应为BEGIN_ARRAY,但为STRING 在第1行第1列的路径$
怎么了?
答案 0 :(得分:0)
此问题是因为Android Studio立即运行,请禁用即时并再次运行。 转到Android Studio设置或首选项(对于MAC)->构建,执行,部署->即时运行。
然后取消选中顶部的“启用即时运行”复选框。