-Débutant-Prb d'editeur de txt sur Android
Salut a tous,
Alors voila je ss sur un tuto sur un autre site et je ss arrivé a un TP ou il faut realiser un editeur de txt.J'ai ecris mon code et Eclipse ne renvoit AUCUNE erreur le prb survient qd je lance l'appli en clicquant sur le "run" d'eclipse.
J'ai copie colle tt mon code pour que vous puissiez le "copier-coller" si vs le voulez,mais seulemt la partie indiquee ds le message d'erreur pose prb apparemt.
Voici le message d'erreur renvoyé:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| 05-18 11:59:52.497: I/dalvikvm(619): Could not find method android.content.pm.PackageManager.getActivityLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
05-18 11:59:52.497: W/dalvikvm(619): VFY: unable to resolve virtual method 318: Landroid/content/pm/PackageManager;.getActivityLogo (Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable;
05-18 11:59:52.497: D/dalvikvm(619): VFY: replacing opcode 0x6e at 0x008b
05-18 11:59:52.497: D/dalvikvm(619): Making a copy of Landroid/support/v7/internal/widget/ActionBarView;.<init> code (1001 bytes)
05-18 11:59:52.497: I/dalvikvm(619): Could not find method android.content.pm.ApplicationInfo.loadLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
05-18 11:59:52.497: W/dalvikvm(619): VFY: unable to resolve virtual method 314: Landroid/content/pm/ApplicationInfo;.loadLogo (Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable;
05-18 11:59:52.497: D/dalvikvm(619): VFY: replacing opcode 0x6e at 0x0099
05-18 11:59:52.577: I/dalvikvm(619): Could not find method android.view.ViewGroup.onConfigurationChanged, referenced from method android.support.v7.internal.widget.AbsActionBarView.onConfigurationChanged
05-18 11:59:52.577: W/dalvikvm(619): VFY: unable to resolve virtual method 7902: Landroid/view/ViewGroup;.onConfigurationChanged (Landroid/content/res/Configuration;)V
05-18 11:59:52.577: D/dalvikvm(619): VFY: replacing opcode 0x6f at 0x0007
05-18 11:59:52.577: D/dalvikvm(619): Making a copy of Landroid/support/v7/internal/widget/AbsActionBarView;.onConfigurationChanged code (148 bytes)
05-18 11:59:52.597: I/dalvikvm(619): Could not find method android.widget.FrameLayout.onConfigurationChanged, referenced from method android.support.v7.internal.widget.ActionBarView$HomeView.onConfigurationChanged
05-18 11:59:52.597: W/dalvikvm(619): VFY: unable to resolve virtual method 8177: Landroid/widget/FrameLayout;.onConfigurationChanged (Landroid/content/res/Configuration;)V
05-18 11:59:52.597: D/dalvikvm(619): VFY: replacing opcode 0x6f at 0x0000
05-18 11:59:52.597: D/dalvikvm(619): Making a copy of Landroid/support/v7/internal/widget/ActionBarView$HomeView;.onConfigurationChanged code (44 bytes)
05-18 11:59:52.647: D/AndroidRuntime(619): Shutting down VM
05-18 11:59:52.647: W/dalvikvm(619): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
05-18 11:59:52.647: E/AndroidRuntime(619): Uncaught handler: thread main exiting due to uncaught exception
05-18 11:59:52.657: E/AndroidRuntime(619): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tuto01.tuto_mapremiereappli/com.tuto01.tuto_mapremiereappli.MainActivity}: java.lang.NullPointerException
05-18 11:59:52.657: E/AndroidRuntime(619): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
05-18 11:59:52.657: E/AndroidRuntime(619): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-18 11:59:52.657: E/AndroidRuntime(619): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-18 11:59:52.657: E/AndroidRuntime(619): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-18 11:59:52.657: E/AndroidRuntime(619): at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 11:59:52.657: E/AndroidRuntime(619): at android.os.Looper.loop(Looper.java:123)
05-18 11:59:52.657: E/AndroidRuntime(619): at android.app.ActivityThread.main(ActivityThread.java:4363)
05-18 11:59:52.657: E/AndroidRuntime(619): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 11:59:52.657: E/AndroidRuntime(619): at java.lang.reflect.Method.invoke(Method.java:521)
05-18 11:59:52.657: E/AndroidRuntime(619): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-18 11:59:52.657: E/AndroidRuntime(619): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-18 11:59:52.657: E/AndroidRuntime(619): at dalvik.system.NativeStart.main(Native Method)
05-18 11:59:52.657: E/AndroidRuntime(619): Caused by: java.lang.NullPointerException
05-18 11:59:52.657: E/AndroidRuntime(619): at com.tuto01.tuto_mapremiereappli.MainActivity.bouton(MainActivity.java:107)
05-18 11:59:52.657: E/AndroidRuntime(619): at com.tuto01.tuto_mapremiereappli.MainActivity.onCreate(MainActivity.java:125)
05-18 11:59:52.657: E/AndroidRuntime(619): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-18 11:59:52.657: E/AndroidRuntime(619): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-18 11:59:52.657: E/AndroidRuntime(619): ... 11 more
05-18 11:59:52.677: I/dalvikvm(619): threadid=7: reacting to signal 3
05-18 11:59:52.677: E/dalvikvm(619): Unable to open stack trace file '/data/anr/traces.txt': Permission denied |
Je pense avoir compris que la partie interessante est la:
Code:
1 2 3
| 05-18 11:59:52.657: E/AndroidRuntime(619): Caused by: java.lang.NullPointerException
05-18 11:59:52.657: E/AndroidRuntime(619): at com.tuto01.tuto_mapremiereappli.MainActivity.bouton(MainActivity.java:107)
05-18 11:59:52.657: E/AndroidRuntime(619): at com.tuto01.tuto_mapremiereappli.MainActivity.onCreate(MainActivity.java:125) |
Voici le code de "MainActivity.java"
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
| package com.tuto01.tuto_mapremiereappli;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.Html;
import android.text.Html.ImageGetter;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity implements ImageGetter{
//Definnition des boutons
Button b_aGras= null,b_aItalique= null,b_aSouligne= null;//a=apparence
Button b_sSmiley1= null,b_sSmiley2= null,b_sSmiley3= null;//s=smiley
Button b_cNoir= null,b_cBleu= null,b_cRouge= null;//c=couleur
//FIN:Definnition des boutons
//--------Gere la mise en forme------------
private OnClickListener miseEnFormeListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
/* Réagir au clic pour les boutons*/
EditText txtR01= (EditText)findViewById(R.id.editTxt);//txR01=text rentre 01//Cette ligne de code ns permet de recuperer le txt rentré
//
if(v.getId()==b_aGras.getId()){
txtR01.setText("<b></b>");
}
if(v.getId()==b_aItalique.getId()){
txtR01.setText("<i></i>");
}
if(v.getId()==b_aSouligne.getId()){
txtR01.setText("<u></u>");
}
//
String txtR02=txtR01.getText().toString();//Cette ligne de code ns permet de convertir le txt rentre en "String"
TextView txtV=(TextView)findViewById(R.id.viewTxt);//On attribut a une variable "l'emplacemt" du txtView
txtV.setText(Html.fromHtml(txtR02));//Ca ls permet de convertir ce qui est ecrit en balis "Html" est ainsi d'afficher le resultat
}
};
//--------FIN:Gere la mise en forme--------
@Override
public Drawable getDrawable(String source) {
// TODO Auto-generated method stub
return null;
}
//--------Gere la couleur------------------
private OnClickListener couleurListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
/* Réagir au clic pour les boutons*/
EditText txtR01= (EditText)findViewById(R.id.editTxt);//txR01=text rentre 01//Cette ligne de code ns permet de recuperer le txt rentré
//
if(v.getId()==b_cNoir.getId()){
txtR01.setText("<font color=#000000></font>");
b_cBleu.setEnabled(false);
b_cRouge.setEnabled(false);
}
if(v.getId()==b_cBleu.getId()){
txtR01.setText("<font color=#0000FF></font>");
b_cNoir.setEnabled(false);
b_cRouge.setEnabled(false);
}
if(v.getId()==b_cRouge.getId()){
txtR01.setText("<font color=#FF0000></font>");
b_cNoir.setEnabled(false);
b_cBleu.setEnabled(false);
}
//
String txtR02=txtR01.getText().toString();//Cette ligne de code ns permet de convertir le txt rentre en "String"
TextView txtV=(TextView)findViewById(R.id.viewTxt);//On attribut a une variable "l'emplacemt" du txtView
txtV.setText(Html.fromHtml(txtR02));//Ca ls permet de convertir ce qui est ecrit en balis "Html" est ainsi d'afficher le resultat
}
};
//--------FIN:Gerer la couleur-------------
//----Def des actions pour chaque touche---
private void bouton(){
//L'Apparence
b_aGras = (Button) findViewById(R.id.b_aGras);
b_aItalique = (Button) findViewById(R.id.b_aItalique);
b_aSouligne = (Button) findViewById(R.id.b_aSouligne);
//Les Smileys
b_sSmiley1 = (Button) findViewById(R.id.b_sSmiley1);
b_sSmiley2 = (Button) findViewById(R.id.b_sSmiley2);
b_sSmiley3 = (Button) findViewById(R.id.b_sSmiley3);
//La Couleur
b_cNoir = (Button) findViewById(R.id.b_cNoir);
b_cBleu = (Button) findViewById(R.id.b_cBleu);
b_cRouge = (Button) findViewById(R.id.b_cRouge);
//
//
b_aGras.setOnClickListener(miseEnFormeListener);
b_aItalique.setOnClickListener(miseEnFormeListener);
b_aSouligne.setOnClickListener(miseEnFormeListener);
//
b_cNoir.setOnClickListener(couleurListener);
b_cBleu.setOnClickListener(couleurListener);
b_cRouge.setOnClickListener(couleurListener);
}
//----FIN:Def des actions pour chaque touche---
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText txtR01= (EditText)findViewById(R.id.editTxt);
bouton();
//----Ce qui s'affichera automatiquement--------
if (!txtR01.getText().toString().equals("")) {
//-------Gere ce qui se passe automatiquement------------
TextWatcher watcherTxt=new TextWatcher(){
EditText txtR01= (EditText)findViewById(R.id.editTxt);
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
String txtR02=txtR01.getText().toString();//Cette ligne de code ns permet de convertir le txt rentre en "String"
TextView txtV=(TextView)findViewById(R.id.viewTxt);//On attribut a une variable "l'emplacemt" du txtView
txtV.setText(Html.fromHtml(txtR02));//Ca ls permet de convertir ce qui est ecrit en balis "Html" est ainsi d'afficher le resultat
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
String txtR02=txtR01.getText().toString();//Cette ligne de code ns permet de convertir le txt rentre en "String"
TextView txtV=(TextView)findViewById(R.id.viewTxt);//On attribut a une variable "l'emplacemt" du txtView
txtV.setText(Html.fromHtml(txtR02));//Ca ls permet de convertir ce qui est ecrit en balis "Html" est ainsi d'afficher le resultat
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
String txtR02=txtR01.getText().toString();//Cette ligne de code ns permet de convertir le txt rentre en "String"
TextView txtV=(TextView)findViewById(R.id.viewTxt);//On attribut a une variable "l'emplacemt" du txtView
txtV.setText(Html.fromHtml(txtR02));//Ca ls permet de convertir ce qui est ecrit en balis "Html" est ainsi d'afficher le resultat
}
};
//-------FIN:Gere ce qui se passe automatiquement----------
txtR01.addTextChangedListener(watcherTxt);
//----FIN/Ce qui s'affichera automatiquement----
}
//Condition si l'affichage ne marche pas------------
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
//----Fin:Condition si l'affichage ne marche pas----
}
//---------------------------------------*****Methode Par Défaul au démarrage*****----------------------------------------------
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
//---------------------------------------*****FIN:Methode Par Défaul au démarrage*****---------------------------------------
} |
Et celui de mon fichier "XML":
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fond"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.tuto01.tuto_mapremiereappli.MainActivity$PlaceholderFragment" >
<!-- Ce layout contiendra tt les autres -->
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<!-- Ce layout contient l'aspect du texte -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/b_aGras"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gras"
android:layout_gravity="center_horizontal"
></Button>
<Button
android:id="@+id/b_aItalique"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Italique"
android:layout_gravity="center_horizontal"
></Button>
<Button
android:id="@+id/b_aSouligne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Souligné"
android:layout_gravity="center_horizontal"
></Button>
</LinearLayout>
<!-- Ce layout contient les Smiley -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Les Smileys:" >
</TextView>
<ImageButton
android:id="@+id/b_sSmiley1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/smiley1"
android:contentDescription="smiley clein d'oeil" ></ImageButton>
<ImageButton
android:id="@+id/b_sSmiley2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/smiley2"
android:contentDescription="smiley sourire" ></ImageButton>
<ImageButton
android:id="@+id/b_sSmiley3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/smiley3"
android:contentDescription="smiley MDR" ></ImageButton>
</LinearLayout>
<!-- FIN:Ce layout contient les Smiley -->
<!-- Ce layout contient la couleur du txt(ss forme de "checkBox") -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<CheckBox
android:id="@+id/b_cNoir"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:checked="true"
android:layout_gravity="center_horizontal"
android:text="Noir"></CheckBox>
<CheckBox
android:id="@+id/b_cBleu"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="Bleu"></CheckBox>
<CheckBox
android:id="@+id/b_cRouge"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="Rouge"></CheckBox>
</LinearLayout>
<!-- FIN:Ce layout contient la couleur du txt(ss forme de "checkBox" )-->
<!--Ce bouton reduira le menu des options -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Réduire"
android:layout_gravity="center_horizontal" ></Button>
<!--FIN:Ce bouton reduira le menu des options -->
<!-- Ce layout contient,est l'endroit ou est tape le txt -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edition:" />
<EditText
android:id="@+id/editTxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Zone de saisie."
android:inputType="textMultiLine"
android:lines="5">
</EditText>
</LinearLayout>
<!-- FIN:Ce layout contient,est l'endroit ou est tape le txt -->
<!-- Ce layout contient Apercu de ce qui est tapé -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prévisualisation:" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/viewTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
</LinearLayout>
<!-- FIN:Ce layout contient Apercu de ce qui est tapé -->
</LinearLayout>
<!-- FIN:Ce layout contiendra tt les autres -->
</RelativeLayout> |
Si vous voulez plus demandez :)
Voila en esperant que vs puissiez m'ai der la j'en ai marre je vois vraimt pas commt resoudre le prb.:arf:
Tchao.