salut les informaticiens , je veux passer des donnés entre mes deux activity mes ça n'a pas marchait avec ce code
erreur : java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { cmp=ttstpackage.tttst/.EnterDataActivity (has extras) }} to activity {ttstpackage.tttst/ttstpackage.tttst.MyActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3319)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2729)
************at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
************at android.app.ActivityThread.access$600(ActivityThread.java:141)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5039)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:511)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
************at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at ttstpackage.tttst.MyActivity.onActivityResult(MyActivity.java:75)
at android.app.Activity.dispatchActivityResult(Activity.java:5293)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3315)
************at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2729)
************at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
************at android.app.ActivityThread.access$600(ActivityThread.java:141)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5039)
************at java.lang.reflect.Method.invokeNative(Native Method)
voila le code :
EnterDataActivity :
MyActivity :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class EnterDataActivity extends Activity { EditText edit_name; EditText edit_dated, edit_datef; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.enter_data); edit_name = (EditText) findViewById(R.id.et_person_name); edit_dated = (EditText) findViewById(R.id.et_person_pin); edit_datef = (EditText) findViewById(R.id.et_person_pin2); } public void onClickAdd (View btnAdd) { String pName = edit_name.getText().toString(); int pdated = Integer.parseInt(edit_dated.getText().toString()); int pdatef = Integer.parseInt(edit_datef.getText().toString()); if ( pName.length() != 0 && pdated != 0 && pdatef != 0 ) { Intent newIntent = getIntent(); newIntent.putExtra("tag_pname", pName); newIntent.putExtra("tag_pdated", pdated); newIntent.putExtra("tag_pdatef", pdatef); this.setResult(RESULT_OK, newIntent); finish(); } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class MyActivity extends Activity { private CustomCursorAdapter customAdapter; private ProjetHelper databaseHelper; private static final int ENTER_DATA_REQUEST_CODE = 1; private ListView listView; String projetName; int dated,datef; private static final String TAG = MyActivity.class.getSimpleName(); /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); databaseHelper = new ProjetHelper(this); listView = (ListView) findViewById(R.id.list_data); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.d(TAG, "clicked on item: " + position); } }); // Database query can be a time consuming task .. // so its safe to call database query in another thread // Handler, will handle this stuff for you <img src="http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif?m=1129645325g" alt=":)" class="wp-smiley"> new Handler().post(new Runnable() { @Override public void run() { customAdapter = new CustomCursorAdapter(MyActivity.this, databaseHelper.getAllData()); listView.setAdapter(customAdapter); } }); } public void onClickEnterData(View btnAdd) { startActivityForResult(new Intent(this, EnterDataActivity.class), ENTER_DATA_REQUEST_CODE); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == ENTER_DATA_REQUEST_CODE && resultCode == RESULT_OK) { projetName=getIntent().getExtras().getString("tag_pname"); dated=getIntent().getExtras().getInt("tag_pdated"); datef= getIntent().getExtras().getInt("tag_pdatef"); MesProjets p = new MesProjets(dated,datef,projetName); databaseHelper.insertprojet( p); //customAdapter.changeCursor(databaseHelper.getAllData()); } } public class CustomCursorAdapter extends CursorAdapter { public CustomCursorAdapter(Context context, Cursor c) { super(context, c); } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { // when the view will be created for first time, // we need to tell the adapters, how each item will look LayoutInflater inflater = LayoutInflater.from(parent.getContext()); View retView = inflater.inflate(R.layout.single_row_item, parent, false); return retView; } @Override public void bindView(View view, Context context, Cursor cursor) { // here we are setting our data // that means, take the data from the cursor and put it in views TextView textViewProjetName = (TextView) view.findViewById(R.id.tv_person_name); textViewProjetName.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1)))); TextView textViewProjetdated = (TextView) view.findViewById(R.id.tv_person_pin); textViewProjetdated.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(2)))); TextView textViewProjetdatef = (TextView) view.findViewById(R.id.tv_person_pin2); textViewProjetdatef.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(3)))); } } }
Partager