我是新来的Java和我开始代码Android的应用程序,但我有一个错误,我认为问题是关于意图过滤器,但我真的不知道..我没有在这里了解任何单一的事情我可以如何执行我的水平?我的代码是一个很好的开始?意外的错误,同时启动应用程序
错误消息:
$ adb shell am start -n "test.beta1/test.beta1.MainActivity" -a
android.intent.action.MAIN -c android.intent.category.LAUNCHER
Unexpected error while executing: am start -n
"test.beta1/test.beta1.MainActivity" -a android.intent.action.MAIN -c
android.intent.category.LAUNCHER
Error while Launching activity
主要活动代码(更新):
package test.beta1;
import android.content.Intent;
import android.media.Image;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity implements
View.OnClickListener{
private static final int RESULT_LOAD_IMAGE = 1;
ImageView imageToUpload;
Button bUploadImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageToUpload = (ImageView) findViewById(R.id.imageToUpload);
bUploadImage = (Button) findViewById(R.id.etUploadName);
imageToUpload.setOnClickListener(this);
bUploadImage.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.imageToUpload:
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent,RESULT_LOAD_IMAGE);
break;
case R.id.bUploadImage:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data !=
null){
Uri selectedImage = data.getData();
imageToUpload.setImageURI(selectedImage);
}
}
}
activity_main.xml中代码:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageToUpload"
android:layout_gravity="center_horizontal"
android:layout_width="150dp"
android:layout_height="150dp" />
<EditText
android:id="@+id/etUploadName"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/bUploadImage"
android:text="Upload Image"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
请,你能解释一下解决这个问题问题?
尝试运行ADB日志时,您应该有一个堆栈跟踪。你能提供日志吗? – Tancho
事件日志:15/10/17 上午12点50分\t摇篮同步完成 上午01时19 \t执行任务:[:应用程序:assembleDebug] 上午01时19 \t摇篮建立成品在5秒4个错误362ms 上午01点20分\t执行任务:[:应用程序:assembleDebug]在2秒261ms 上午01点26分\t执行任务 上午01点20分\t摇篮建立成品3误差(S):[:应用程序:assembleDebug] 1:26 AM \t Gradle build in 1s285ms 1:27 AM \t执行任务:[:app:assembleDebug] 1:27 AM \t Gradle build in 4s4 24MS 上午01时28分\t执行任务:[:应用:assembleDebug] 上午01时28分\t摇篮建设完成了1s879ms 上午01点29 \t会议“应用”:错误下水活动 –
我已经添加在gradle这个控制台该帖子(编辑它) –