الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مساعدة في startActivityForResult

بدأه Bo3WaaS في 17 مايو 2012 · 1 رد · 852 مشاهدة · في Android
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

أحاول استخدام الدالة startActivityForResult() ولكن أحصل على الخطأ التالي :

05-17 13:51:31.879: E/AndroidRuntime(336): java.lang.RuntimeException: Unable to start activity ComponentInfo{university.hci.exceptiontutorial/university.hci.exceptiontutorial.FontColor}: java.lang.NullPointerException

كود الاستدعاء :

Intent i = new Intent(ExceptionTutorialActivity.this,FontColor.class);
			startActivityForResult(i, COLOR);

الكلاس الذي أريد استدعاءه :

package university.hci.exceptiontutorial;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class FontColor extends Activity implements OnClickListener{


	private Button black,red,yellow,green,grey,blue;
	private Intent iColor;
	private Bundle bColor;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		iColor = new Intent();
		bColor = new Bundle();

		black = (Button) findViewById(R.id.black);
		black.setTextColor(Color.BLACK);

		red = (Button) findViewById(R.id.red);
		red.setTextColor(Color.RED);

		yellow = (Button) findViewById(R.id.yellow);
		yellow.setTextColor(Color.YELLOW);

		green = (Button) findViewById(R.id.green);
		green.setTextColor(Color.GREEN);

		grey = (Button) findViewById(R.id.grey);
		grey.setTextColor(Color.GRAY);

		blue = (Button) findViewById(R.id.blue);
		blue.setText(Color.BLUE);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()){
		case R.id.black:
			bColor.putString("color", "black");
			iColor.putExtras(bColor);
			setResult(RESULT_OK, iColor);
			finish();
			break;
		case R.id.red:
			bColor.putString("color", "red");
			iColor.putExtras(bColor);
			setResult(RESULT_OK, iColor);
			finish();
			break;
		case R.id.yellow:
			bColor.putString("color", "yellow");
			iColor.putExtras(bColor);
			setResult(RESULT_OK, iColor);
			finish();
			break;
		case R.id.green:
			bColor.putString("color", "green");
			iColor.putExtras(bColor);
			setResult(RESULT_OK, iColor);
			finish();
			break;
		case R.id.grey:
			bColor.putString("color", "grey");
			iColor.putExtras(bColor);
			setResult(RESULT_OK, iColor);
			finish();
			break;
		case R.id.blue:
			bColor.putString("color", "blue");
			iColor.putExtras(bColor);
			setResult(RESULT_OK, iColor);
			finish();
			break;
		}
	}

}
#2

تم حل المشكلة بحمد الله :)

مواضيع مشابهة