Je suis nouveau à Java et j'ai commencé à coder une application pour Android, mais j'ai une erreur, je pense que le problème est sur le filtre d'intention, mais je ne suis pas sûr .. comprendre une seule chose ici. Comment je pourrais effectuer mon niveau? Mon code est-il un bon point de départ?Erreur inattendue lors du lancement de l'application
Message d'erreur:
$ 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
code d'activité principale (mise à jour):
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);
}
}
}
Code 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>
S'il vous plaît, pouvez-vous expliquer comment pour résoudre ce problème problème?
Vous devez avoir une trace de pile dans les journaux ADB lorsque vous tentez de l'exécuter. pouvez-vous fournir le journal? – Tancho
journal des événements: 15/10/17 00h50 \t synchronisation Gradle terminé 01h19 \t tâches d'exécution: [: application: assembleDebug] 01h19 \t Gradle construire fini avec 4 erreur (s) dans 5 s 362ms 01:20 \t tâches d'exécution: [: application: assembleDebug] 01:20 \t Gradle construction fini avec 3 erreur (s) dans 2s 261ms 01:26 \t tâches d'exécution: [: application: assembleDebug] 1:26 AM \t Construction de la finition terminée en 1s285ms 1:27 AM \t Exécution des tâches: [: app: assembleDebug] 1:27 AM \t Construction de la finition en 4s4 24ms 01h28 \t tâches d'exécution: [: application: assembleDebug] 01h28 \t Gradle construire fini dans 1s879ms 01h29 \t 'app' Session: Erreur activité de lancement –
J'ai ajouté la console gradle dans le poste (édité) –