J
JoceBiniou
Membre
- Inscrit
- 11 Décembre 2015
- Messages
- 2
- Points
- 0
- #1
Bonjour,
Je suis débutant et j'ai du mal à debbuger. Je ne comprend pas les messages comme ceux du langage C 8/ .
Voici mes messages d'erreur précédé de mon main.java, XML, Strings et manifeste :
package com.example.jocelyn.micro;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.formation.micro.R;
class Main extends Activity implements OnClickListener, OnCompletionListener {
/** Called when the activity is first created. */
boolean isPlaying = false;
MediaPlayer player;
FileInputStream fis;
boolean isRecording = false;
MediaRecorder recorder;
FileOutputStream fos;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((Button)this.findViewById(R.id.btn1)).setOnClickListener(this);
((Button)this.findViewById(R.id.btn2)).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn1:
if(isRecording){
EndRecord();
}else{
BeginRecord();
}
break;
case R.id.btn2:
if(isPlaying){
EndPlayback();
}else{
BeginPlayback();
}
break;
}
}
public void EndPlayback(){
player.stop();
player.reset();
player.release();
isPlaying=false;
try {
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
((Button)this.findViewById(R.id.btn2)).setText("Rejouer");
}
public void BeginPlayback(){
try {
fis = this.openFileInput("sound.dat");
player = new MediaPlayer();
player.setOnCompletionListener(this);
player.setDataSource(fis.getFD());
player.prepare();
player.start();
isPlaying=true;
((Button)this.findViewById(R.id.btn2)).setText("Arreter");
} catch (Exception e) {
e.printStackTrace();
}
}
public void BeginRecord(){
try {
fos = this.openFileOutput("sound.dat",Context.MODE_WORLD_READABLE|Context.MODE_WORLD_WRITEABLE);
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(fos.getFD());
recorder.prepare();
recorder.start();
isRecording=true;
((Button)this.findViewById(R.id.btn1)).setText("Arreter");
} catch (Exception e) {
e.printStackTrace();
}
}
public void EndRecord(){
recorder.stop();
recorder.reset();
recorder.release();
isRecording=false;
try {
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
((Button)this.findViewById(R.id.btn1)).setText("Enregistrer");
}
@Override
public void onCompletion(MediaPlayer mp) {
EndPlayback();
}
}
XML main
Manifeste
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android
rientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/hello"/>
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Enregistrer" android:id="@+id/btn1"/>
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Rejouer" android:id="@+id/btn2"/>
</LinearLayout>
String
?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="hello">Hello World, Main!</string>
<string name="app_name">micro</string>
<string name="action_settings">action_settings</string>
</resources>
Message d'erreur :
12-11 16:09:10.800 30122-30122/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jocelyn.micro, PID: 30122
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.jocelyn.micro/com.example.jocelyn.micro.Main}: java.lang.IllegalAccessException: class com.example.jocelyn.micro.Main is not accessible from class android.app.Instrumentation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2964)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.IllegalAccessException: class com.example.jocelyn.micro.Main is not accessible from class android.app.Instrumentation
at java.lang.Class.newInstance(Class.java:1669)
at android.app.Instrumentation.newActivity(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2954)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Je suis débutant et j'ai du mal à debbuger. Je ne comprend pas les messages comme ceux du langage C 8/ .
Voici mes messages d'erreur précédé de mon main.java, XML, Strings et manifeste :
package com.example.jocelyn.micro;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.formation.micro.R;
class Main extends Activity implements OnClickListener, OnCompletionListener {
/** Called when the activity is first created. */
boolean isPlaying = false;
MediaPlayer player;
FileInputStream fis;
boolean isRecording = false;
MediaRecorder recorder;
FileOutputStream fos;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((Button)this.findViewById(R.id.btn1)).setOnClickListener(this);
((Button)this.findViewById(R.id.btn2)).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn1:
if(isRecording){
EndRecord();
}else{
BeginRecord();
}
break;
case R.id.btn2:
if(isPlaying){
EndPlayback();
}else{
BeginPlayback();
}
break;
}
}
public void EndPlayback(){
player.stop();
player.reset();
player.release();
isPlaying=false;
try {
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
((Button)this.findViewById(R.id.btn2)).setText("Rejouer");
}
public void BeginPlayback(){
try {
fis = this.openFileInput("sound.dat");
player = new MediaPlayer();
player.setOnCompletionListener(this);
player.setDataSource(fis.getFD());
player.prepare();
player.start();
isPlaying=true;
((Button)this.findViewById(R.id.btn2)).setText("Arreter");
} catch (Exception e) {
e.printStackTrace();
}
}
public void BeginRecord(){
try {
fos = this.openFileOutput("sound.dat",Context.MODE_WORLD_READABLE|Context.MODE_WORLD_WRITEABLE);
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(fos.getFD());
recorder.prepare();
recorder.start();
isRecording=true;
((Button)this.findViewById(R.id.btn1)).setText("Arreter");
} catch (Exception e) {
e.printStackTrace();
}
}
public void EndRecord(){
recorder.stop();
recorder.reset();
recorder.release();
isRecording=false;
try {
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
((Button)this.findViewById(R.id.btn1)).setText("Enregistrer");
}
@Override
public void onCompletion(MediaPlayer mp) {
EndPlayback();
}
}
XML main
Code:
S'il vous plaît,
Connexion
ou
S'inscrire
to view codes content!
Manifeste
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android
<TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/hello"/>
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Enregistrer" android:id="@+id/btn1"/>
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Rejouer" android:id="@+id/btn2"/>
</LinearLayout>
String
?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="hello">Hello World, Main!</string>
<string name="app_name">micro</string>
<string name="action_settings">action_settings</string>
</resources>
Message d'erreur :
12-11 16:09:10.800 30122-30122/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jocelyn.micro, PID: 30122
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.jocelyn.micro/com.example.jocelyn.micro.Main}: java.lang.IllegalAccessException: class com.example.jocelyn.micro.Main is not accessible from class android.app.Instrumentation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2964)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.IllegalAccessException: class com.example.jocelyn.micro.Main is not accessible from class android.app.Instrumentation
at java.lang.Class.newInstance(Class.java:1669)
at android.app.Instrumentation.newActivity(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2954)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)