ListView Item OnItemClick crashing in ListView Adapter Class - java

I've been trying to get my list view to work for quite some time now, I just changed my listener from onClick to onItemClick to handle listview items better but the app crashes once again, my code below, any help would be appreciated.
Class:
public class ListViewAdapterProduct extends BaseAdapter {
Context mContext;
ListView listView = (ListView) findViewById(R.id.listview1);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id){
Resources res = mContext.getResources();
productTitleArray = res.getStringArray(R.array.titles_product);
for (String productTitle : productTitleArray)
{
if(productTitle.equals("productOne"))
{
Log.d("Msg", "Found");
}
else
{
Log.d("Msg", "Not Found");
}
}
}
});
My previous post:
Compare XML String From Java Class When Item In ListView Is Clicked
Logcat:
03-30 16:40:39.027: E/AndroidRuntime(811): FATAL EXCEPTION: main
03-30 16:40:39.027: E/AndroidRuntime(811): java.lang.NullPointerException
03-30 16:40:39.027: E/AndroidRuntime(811): at com.twostarii.test.ListViewAdapterproduct.getView(ListViewAdapterproduct.java:91)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.AbsListView.obtainView(AbsListView.java:2159)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.ListView.makeAndAddView(ListView.java:1831)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.ListView.fillDown(ListView.java:674)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.ListView.fillFromTop(ListView.java:735)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.ListView.layoutChildren(ListView.java:1652)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.AbsListView.onLayout(AbsListView.java:1994)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.View.layout(View.java:14008)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewGroup.layout(ViewGroup.java:4373)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.View.layout(View.java:14008)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewGroup.layout(ViewGroup.java:4373)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.View.layout(View.java:14008)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewGroup.layout(ViewGroup.java:4373)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.View.layout(View.java:14008)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewGroup.layout(ViewGroup.java:4373)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.View.layout(View.java:14008)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewGroup.layout(ViewGroup.java:4373)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.Choreographer.doFrame(Choreographer.java:532)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.os.Handler.handleCallback(Handler.java:725)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.os.Handler.dispatchMessage(Handler.java:92)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.os.Looper.loop(Looper.java:137)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-30 16:40:39.027: E/AndroidRuntime(811): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 16:40:39.027: E/AndroidRuntime(811): at java.lang.reflect.Method.invoke(Method.java:511)
03-30 16:40:39.027: E/AndroidRuntime(811): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-30 16:40:39.027: E/AndroidRuntime(811): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-30 16:40:39.027: E/AndroidRuntime(811): at dalvik.system.NativeStart.main(Native Method)
Activity:
public class MainActivityproduct extends MainActivity {
ListView list;
ListViewAdapterproduct adapter;
EditText editsearch;
String[] position;
String[] productTitles;
String[] productDescriptions;
int[] images={
R.drawable.list_product_one,
R.drawable.list_product_two,
R.drawable.list_product_three,
};
ArrayList<ClassproductList> arraylist = new ArrayList<ClassproductList>();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
position = new String[] { "1", "2", "3"};
Resources res = getResources();
productTitles = res.getStringArray(R.array.titles_product);
productDescriptions = res.getStringArray(R.array.descriptions_product);
list = (ListView) findViewById(R.id.listview1);
list.setAdapter(adapter);
for (int i = 0; i < position.length; i++)
{
ClassproductList wp = new ClassproductList(productTitles[i], productDescriptions[i],images[i]);
arraylist.add(wp);
}
adapter = new ListViewAdapterproduct(this, arraylist);
list.setAdapter(adapter);
editsearch = (EditText) findViewById(R.id.search);
editsearch.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable arg0) {
String text = editsearch.getText().toString().toLowerCase(Locale.getDefault());
adapter.filter(text);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

You have declared the mContext, but you have not initialized it.
You can do this in the constructor of your adapter:
public class ListViewAdapterProduct extends BaseAdapter {
Context mContext;
// the construcor that initializes the context
public ListViewAdapterProduct(Context c){
mContext = c;
}
...
However, the trace that you have posted, suggest that the problem is in your adapter's getView() method, on line 91. You should check that also.
ListViewAdapterproduct.getView(ListViewAdapterproduct.java:91)
Edit:
list.setAdapter(adapter);
In this line the adapter is null, you did not initialize it... (you set your adapter twice, first with null).
It is a good practise to define your variables locally, and make them class variable only when you actually need it. This way its harder to forget about initialization.

you have a problem in Context mContext; is null
in your activity set mContext = this; so mContext would be the activity context you will be able to use the resources
this is the correct code :
since your already sent this in your adapter you need to catch it there
public class ListViewAdapterProduct extends BaseAdapter {
Context mContext;
ArrayList<ClassproductList> arraylist;
ListView listView = (ListView) findViewById(R.id.listview1);
//add this
public ListViewAdapterProduct (Context mContext,ArrayList<ClassproductList> arraylist)
{
this.mContext = mContext;
this.arraylist = arraylist;
}

SOLVED !!!
I changed back from onItemClick (complicated to use with custom adapter) to onClick (simple to use with custom adapter) and applied:
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String mytitle=holder.title.getText().toString();
if(mytitle.equals("ProductOne")){
Intent intent1 = new Intent(mContext, ProductClass.ProductOne);
mContext.startActivity(intent1);
...
}
}
Had to add:
String mytitle=holder.title.getText().toString();

Related

Custom pageradapter class getting Null Pointer Exception

My custom pageadapter is getting NullPointerException at instantiateItem. However, if I use this adapter as an inner-class then there is no error.
My custom pageadapter class
class MyPagesAdapter extends PagerAdapter {
String mPageData[]; //Stores the text to swipe.
LayoutInflater inflater; //Used to create individual pages
ViewPager vp;
public MyPagesAdapter(String pageData[])
{
mPageData = pageData;
}
#Override
public int getCount() {
return mPageData.length;
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
View page = inflater.inflate(R.layout.page, null);
((TextView)page.findViewById(R.id.textMessage)).setText(mPageData[position]);
((ViewPager) container).addView(page, 0);
return page;
}
#Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0==(View)arg1;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((View) object);
object=null;
}
}
Here is mainActivity class
public class MainActivity extends Activity {
String pageData[]; //Stores the text to swipe.
LayoutInflater inflater; //Used to create individual pages
ViewPager vp; //Reference
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pageData=getResources().getStringArray(R.array.desserts);
//get an inflater to be used to create single pages
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Reference ViewPager defined in activity
vp=(ViewPager)findViewById(R.id.viewPager);
//set the adapter that will create the individual pages
vp.setAdapter(new MyPagesAdapter(pageData));
}}
Here is Error:
07-03 10:02:07.269: D/dalvikvm(1391): Not late-enabling CheckJNI (already on)
07-03 10:02:07.289: D/AndroidRuntime(1391): Shutting down VM
07-03 10:02:07.289: W/dalvikvm(1391): threadid=1: thread exiting with uncaught exception (group=0xb5004180)
07-03 10:02:07.339: E/AndroidRuntime(1391): FATAL EXCEPTION: main
07-03 10:02:07.339: E/AndroidRuntime(1391): java.lang.NullPointerException
07-03 10:02:07.339: E/AndroidRuntime(1391): at com.example.viewpager2.MyPagesAdapter.instantiateItem(MyPagesAdapter.java:30)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:869)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.support.v4.view.ViewPager.populate(ViewPager.java:1019)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.support.v4.view.ViewPager.populate(ViewPager.java:951)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1473)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.View.measure(View.java:12723)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.View.measure(View.java:12723)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.View.measure(View.java:12723)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.View.measure(View.java:12723)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-03 10:02:07.339: E/AndroidRuntime(1391): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.View.measure(View.java:12723)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.os.Handler.dispatchMessage(Handler.java:99)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.os.Looper.loop(Looper.java:137)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-03 10:02:07.339: E/AndroidRuntime(1391): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 10:02:07.339: E/AndroidRuntime(1391): at java.lang.reflect.Method.invoke(Method.java:511)
07-03 10:02:07.339: E/AndroidRuntime(1391): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-03 10:02:07.339: E/AndroidRuntime(1391): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-03 10:02:07.339: E/AndroidRuntime(1391): at dalvik.system.NativeStart.main(Native Method)
07-03 10:02:07.780: I/dalvikvm(1391): threadid=3: reacting to signal 3
07-03 10:02:07.780: I/dalvikvm(1391): Wrote stack traces to '/data/anr/traces.txt'
07-03 10:02:07.958: I/dalvikvm(1391): threadid=3: reacting to signal 3
07-03 10:02:07.958: I/dalvikvm(1391): Wrote stack traces to '/data/anr/traces.txt'
Update:
one solution could be passing the inflater to pageadapter class from activity
vp.setAdapter(new MyPagesAdapter(pageData,inflater));
in pageadapter class
public MyPagesAdapter(String pageData[], LayoutInflater minflater)
{
mPageData = pageData;
inflater = minflater;
}
or simply stablish Layoutinflater in pageadapter class
LayoutInflater inflater = (LayoutInflater) container.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

Null Pointer Exception while setting value of TextView in an Array Adapter class - Android

I'm getting a NullPointerException while trying to start an Activity which contains a ListView .
In the getView method of the adapter class, the exception happens when the setText function of a textView is being called .
The code bellow is my adapter class:
public class QuestionsListAdapter extends ArrayAdapter<Question> {
Context context;
List<Question> questions;
public QuestionsListAdapter(Context context, List<Question> questions){
super(context, R.layout.list_item_question, questions);
this.context = context;
this.questions = questions;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = vi.inflate(R.layout.list_item_question, null);
Question question = questions.get(position);
TextView tv = (TextView) view.findViewById(R.id.question_list_item_string);
Log.i(TableCreator.LOG_TAG, question.toString()); //this works fine and the string is not null .
tv.setText(question.toString()+""); //NULL POINTER EXCEPTION .
return view;
}
}
As you see, I've logged the string in the logcat and it works just fine, but the next line makes the mistake .
And this is the logcat output:
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist I/Operation Checklist﹕ |-Question-> id:1 summary:mySummary comment:myComment solution:mySolution ownerList:dummyOwner
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist D/AndroidRuntime﹕ Shutting down VM
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb0f5f648)
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at org.kabiri.operationchecklist.adapter.QuestionsListAdapter.getView(QuestionsListAdapter.java:43)
at android.widget.AbsListView.obtainView(AbsListView.java:2177)
at android.widget.ListView.makeAndAddView(ListView.java:1840)
at android.widget.ListView.fillDown(ListView.java:675)
at android.widget.ListView.fillFromTop(ListView.java:736)
at android.widget.ListView.layoutChildren(ListView.java:1655)
at android.widget.AbsListView.onLayout(AbsListView.java:2012)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:502)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
The logcat shows that the error happens on this line of my adapter class:
tv.setText(question.toString()+"");
I really appreciate your help .
You already know where the problem is!
tv.setText(question.toString()+"");
is causing the NPE that means the TextView tv is null. And that means that the line
TextView tv = (TextView) view.findViewById(R.id.question_list_item_string);
is not able to find the TextView. Check the question_list_item_string id and make sure it matches the id in your list_item_question.xml file

Getting a wierd error i dont understand when creating a button

everything is mainly explained in the title ill go in as much detail as i can. I am making an android game app i created a unique id for a circle that is drawn in canvas in the DrawingView class since this cannot be referenced in xml i had to create the id as an int in java so that java could find the id and use it as the button. Im sure you are all very confused by now i will continue will putting in my best effort to explain. below is the code for the Main file that gets called
public class Main extends Activity {
DrawingView v;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
LinearLayout layout1 = new LinearLayout (this);
FrameLayout game = new FrameLayout(this);
DrawingView v = new DrawingView (this);
TextView myText = new TextView(this);
int w = getResources().getInteger(DrawingView.redColor);
Button redCircle = (Button) findViewById(w);
redCircle.setWidth(300);
redCircle.setText("Start Game");
layout1.addView(myText);
layout1.addView(redCircle);
//redCircle.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
game.addView(v);
game.addView(layout1);
setContentView(game);
redCircle.setOnClickListener((OnClickListener) this);
}
public void onClick(View v) {
Intent intent = new Intent(this, Main.class);
startActivity(intent);
// re-starts this activity from game-view. add this.finish(); to remove from stack
}
#Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and not really neccessary but to help you understand what i am trying to accomplish here is the DrawingView class that creates random circles either green or red below.
public class DrawingView extends View {
public DrawingView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
RectF rectf = new RectF(0, 0, 200, 0);
private static final int w = 100;
public static int lastColor = Color.BLACK;
private final Random random = new Random();
private final Paint paint = new Paint();
private final int radius = 230;
private final Handler handler = new Handler();
public static int redColor = Color.RED;
public static int greenColor = Color.GREEN;
private final Runnable updateCircle = new Runnable() {
#Override
public void run() {
lastColor = random.nextInt(2) == 1 ? redColor : greenColor;
paint.setColor(lastColor);
invalidate();
handler.postDelayed(this, 1000);
}
};
#Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
handler.post(updateCircle);
}
#Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
handler.removeCallbacks(updateCircle);
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// your other stuff here
canvas.drawCircle(random.nextInt(canvas.getWidth()-radius/2) + radius/2f, random.nextInt(canvas.getHeight()-radius/2) + radius/2f, radius, paint);
}
//Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
//private int h = 100;
//#SuppressLint("DrawAllocation")
//Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
//Canvas canvas = new Canvas(bmp);
/*
private Object canvas(Bitmap bmp) {
// TODO Auto-generated method stub
return null;
}
*/
}
and more importantly the log cat errors that display after the app crashes
03-30 02:27:27.903: E/AndroidRuntime(3104): FATAL EXCEPTION: main
03-30 02:27:27.903: E/AndroidRuntime(3104): Process: com.Tripps.thesimplegame, PID: 3104
03-30 02:27:27.903: E/AndroidRuntime(3104): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
03-30 02:27:27.903: E/AndroidRuntime(3104): at com.Tripps.thesimplegame.DrawingView.onDraw(DrawingView.java:67)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.draw(View.java:15114)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.updateDisplayListIfDirty(View.java:14048)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.getDisplayList(View.java:14071)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.draw(View.java:14838)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.updateDisplayListIfDirty(View.java:14043)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.getDisplayList(View.java:14071)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.draw(View.java:14838)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.updateDisplayListIfDirty(View.java:14043)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.getDisplayList(View.java:14071)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.draw(View.java:14838)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.updateDisplayListIfDirty(View.java:14043)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.getDisplayList(View.java:14071)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.draw(View.java:14838)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.draw(View.java:15117)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.widget.FrameLayout.draw(FrameLayout.java:592)
03-30 02:27:27.903: E/AndroidRuntime(3104): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2595)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.updateDisplayListIfDirty(View.java:14048)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.View.getDisplayList(View.java:14071)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:266)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:272)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:311)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2492)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2337)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1968)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.Choreographer.doCallbacks(Choreographer.java:580)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.Choreographer.doFrame(Choreographer.java:550)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.os.Handler.handleCallback(Handler.java:739)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.os.Handler.dispatchMessage(Handler.java:95)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.os.Looper.loop(Looper.java:135)
03-30 02:27:27.903: E/AndroidRuntime(3104): at android.app.ActivityThread.main(ActivityThread.java:5221)
03-30 02:27:27.903: E/AndroidRuntime(3104): at java.lang.reflect.Method.invoke(Native Method)
03-30 02:27:27.903: E/AndroidRuntime(3104): at java.lang.reflect.Method.invoke(Method.java:372)
03-30 02:27:27.903: E/AndroidRuntime(3104): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
03-30 02:27:27.903: E/AndroidRuntime(3104): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-30 02:38:46.269: D/OpenGLRenderer(3167): Render dirty regions requested: true
03-30 02:38:46.276: D/(3167): HostConnection::get() New Host Connection established 0xae0add60, tid 3167
03-30 02:38:46.287: D/Atlas(3167): Validating map...
03-30 02:38:46.379: D/(3167): HostConnection::get() New Host Connection established 0xa6c52140, tid 3182
03-30 02:38:46.427: I/OpenGLRenderer(3167): Initialized EGL, version 1.4
03-30 02:38:46.473: D/OpenGLRenderer(3167): Enabling debug mode 0
03-30 02:38:46.550: W/EGL_emulation(3167): eglSurfaceAttrib not implemented
03-30 02:38:46.550: W/OpenGLRenderer(3167): Failed to set EGL_SWAP_BEHAVIOR on surface 0xae0ed4a0, error=EGL_SUCCESS
03-30 03:01:54.523: W/ResourceType(3228): No known package when getting value for resource number 0xffff0000
03-30 03:01:54.523: D/AndroidRuntime(3228): Shutting down VM
03-30 03:01:54.524: E/AndroidRuntime(3228): FATAL EXCEPTION: main
03-30 03:01:54.524: E/AndroidRuntime(3228): Process: com.Tripps.thesimplegame, PID: 3228
03-30 03:01:54.524: E/AndroidRuntime(3228): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Tripps.thesimplegame/com.Tripps.thesimplegame.Main}: android.content.res.Resources$NotFoundException: Resource ID #0xffff0000
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.app.ActivityThread.access$800(ActivityThread.java:144)
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.os.Handler.dispatchMessage(Handler.java:102)
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.os.Looper.loop(Looper.java:135)
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.app.ActivityThread.main(ActivityThread.java:5221)
03-30 03:01:54.524: E/AndroidRuntime(3228): at java.lang.reflect.Method.invoke(Native Method)
03-30 03:01:54.524: E/AndroidRuntime(3228): at java.lang.reflect.Method.invoke(Method.java:372)
03-30 03:01:54.524: E/AndroidRuntime(3228): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
03-30 03:01:54.524: E/AndroidRuntime(3228): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-30 03:01:54.524: E/AndroidRuntime(3228): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0xffff0000
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.content.res.Resources.getValue(Resources.java:1233)
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.content.res.Resources.getInteger(Resources.java:989)
03-30 03:01:54.524: E/AndroidRuntime(3228): at com.Tripps.thesimplegame.Main.onCreate(Main.java:34)
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.app.Activity.performCreate(Activity.java:5933)
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
03-30 03:01:54.524: E/AndroidRuntime(3228): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
03-30 03:01:54.524: E/AndroidRuntime(3228): ... 10 more
03-30 03:03:04.088: W/ResourceType(3288): No known package when getting value for resource number 0xffff0000
03-30 03:03:04.089: D/AndroidRuntime(3288): Shutting down VM
03-30 03:03:04.089: E/AndroidRuntime(3288): FATAL EXCEPTION: main
03-30 03:03:04.089: E/AndroidRuntime(3288): Process: com.Tripps.thesimplegame, PID: 3288
03-30 03:03:04.089: E/AndroidRuntime(3288): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Tripps.thesimplegame/com.Tripps.thesimplegame.Main}: android.content.res.Resources$NotFoundException: Resource ID #0xffff0000
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.app.ActivityThread.access$800(ActivityThread.java:144)
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.os.Handler.dispatchMessage(Handler.java:102)
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.os.Looper.loop(Looper.java:135)
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.app.ActivityThread.main(ActivityThread.java:5221)
03-30 03:03:04.089: E/AndroidRuntime(3288): at java.lang.reflect.Method.invoke(Native Method)
03-30 03:03:04.089: E/AndroidRuntime(3288): at java.lang.reflect.Method.invoke(Method.java:372)
03-30 03:03:04.089: E/AndroidRuntime(3288): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
03-30 03:03:04.089: E/AndroidRuntime(3288): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-30 03:03:04.089: E/AndroidRuntime(3288): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0xffff0000
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.content.res.Resources.getValue(Resources.java:1233)
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.content.res.Resources.getInteger(Resources.java:989)
03-30 03:03:04.089: E/AndroidRuntime(3288): at com.Tripps.thesimplegame.Main.onCreate(Main.java:34)
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.app.Activity.performCreate(Activity.java:5933)
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
03-30 03:03:04.089: E/AndroidRuntime(3288): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
03-30 03:03:04.089: E/AndroidRuntime(3288): ... 10 more
03-30 03:03:34.502: I/Process(3288): Sending signal. PID: 3288 SIG: 9
You are getting error at :
canvas.drawCircle(random.nextInt(canvas.getWidth()-radius/2) + radius/2f, random.nextInt(canvas.getHeight()-radius/2) + radius/2f, radius, paint);
Because the Object canvas do not have width or height (it is null)
Reason :
Your code adds views like :
LinearLayout layout1 = new LinearLayout (this);
FrameLayout game = new FrameLayout(this);
DrawingView v = new DrawingView (this);
TextView myText = new TextView(this);
int w = getResources().getInteger(DrawingView.redColor);
Button redCircle = (Button) findViewById(w);
redCircle.setWidth(300);
redCircle.setText("Start Game");
layout1.addView(myText);
layout1.addView(redCircle);
//redCircle.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
game.addView(v);
game.addView(layout1);
But at the time of
game.addView(v);
v do not have any views referenced so the null object view is added in
game
So pls add some view i.e. Text or Images in v first and then call
game.addView(v);
This is solution for your error

Execute Multi line SQLite query

i am trying to download a .txt file from internet and then read it and execute it.
i had success in downloading, reading and executing a single line query file.
but the problem is i cant execute multi line query from the file. i did some research and they did not suit my needs so i came up with a solution but i cant figure out some errors.
my idea is to convert a .txt file, line by line to a List and then for each String in the List execute a query within sqlite.
here's some of my code :
public void updateDB(View v){
new DownloadFileFromURL().execute(file_url);
File file = new File(Environment
.getExternalStorageDirectory().toString()
+ "/update.txt")
Log.i("UPDATE", "SQL DOWNLOADED");
while(start.equals(true)){
List<String> list = readUpdate2("update.txt");
for (String string : list) {
datasource.executeRaw(string);
Log.i("UPDATE", "EXEC SQL # : " + list.size());
}
file.delete();}}
public List<String> readUpdate2(String url){
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
List<String> list = null;
File file = new File(sdcard,url);
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while((line = br.readLine()) != null) {
// this is where the error happens :
list.add(line);
Log.i("UPDATE", "LINE : " + line);
}
}
catch (IOException e) {
}
return list;
}
the problem is i am stuck with a Nullpointer exception. it says the line is empty.
Here is the logcat :
03-30 18:01:18.965: E/AndroidRuntime(12474): FATAL EXCEPTION: main
03-30 18:01:18.965: E/AndroidRuntime(12474): java.lang.IllegalStateException: Could not execute method of the activity
03-30 18:01:18.965: E/AndroidRuntime(12474): at android.view.View$1.onClick(View.java:3838)
03-30 18:01:18.965: E/AndroidRuntime(12474): at android.view.View.performClick(View.java:4475)
03-30 18:01:18.965: E/AndroidRuntime(12474): at android.view.View$PerformClick.run(View.java:18786)
03-30 18:01:18.965: E/AndroidRuntime(12474): at android.os.Handler.handleCallback(Handler.java:730)
03-30 18:01:18.965: E/AndroidRuntime(12474): at android.os.Handler.dispatchMessage(Handler.java:92)
03-30 18:01:18.965: E/AndroidRuntime(12474): at android.os.Looper.loop(Looper.java:137)
03-30 18:01:18.965: E/AndroidRuntime(12474): at android.app.ActivityThread.main(ActivityThread.java:5493)
03-30 18:01:18.965: E/AndroidRuntime(12474): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 18:01:18.965: E/AndroidRuntime(12474): at java.lang.reflect.Method.invoke(Method.java:525)
03-30 18:01:18.965: E/AndroidRuntime(12474): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
03-30 18:01:18.965: E/AndroidRuntime(12474): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
03-30 18:01:18.965: E/AndroidRuntime(12474): at dalvik.system.NativeStart.main(Native Method)
03-30 18:01:18.965: E/AndroidRuntime(12474): Caused by: java.lang.reflect.InvocationTargetException
03-30 18:01:18.965: E/AndroidRuntime(12474): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 18:01:18.965: E/AndroidRuntime(12474): at java.lang.reflect.Method.invoke(Method.java:525)
03-30 18:01:18.965: E/AndroidRuntime(12474): at android.view.View$1.onClick(View.java:3833)
03-30 18:01:18.965: E/AndroidRuntime(12474): ... 11 more
03-30 18:01:18.965: E/AndroidRuntime(12474): Caused by: java.lang.NullPointerException
03-30 18:01:18.965: E/AndroidRuntime(12474): at com.meemarbashi.meemardictionary.UpdateActivity.readUpdate2(UpdateActivity.java:292)
03-30 18:01:18.965: E/AndroidRuntime(12474): at com.meemarbashi.meemardictionary.UpdateActivity.updateDB(UpdateActivity.java:223)
03-30 18:01:18.965: E/AndroidRuntime(12474): ... 14 more
so basically i am getting no text from the .txt file and then i cannot add anything to my List. what should i do ?
thanks in advance
This is probably the reason of null pointer exception:
List<String> list = null;
Try assigning a new list instead of null

Android Java, getString from the Main Activity to a Fragment Issue

Hi could someone advise me on whats wrong with the following code. The logcat says its in the onCreate method. all seems to be correct in the mainactivity as i have passed the bundle with the string.
#SuppressLint("NewApi")
public class CurrentBookingFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {
View view =inflater.inflate(R.layout.current_booking_fragment, container, false);
Bundle bundle = this.getArguments();
String strtext = this.getArguments().getString("GetStringPUFirstLine");
TextView CurrentBookingFragmentTV = (TextView)view.findViewById(R.id.CurrentBookingFragmentTV);
CurrentBookingFragmentTV.setText(strtext);
return view;
}
}
Here is the log:
03-30 21:59:30.385: E/AndroidRuntime(30843): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
03-30 21:59:30.385: E/AndroidRuntime(30843): at dalvik.system.NativeStart.main(Native Method)
03-30 21:59:30.385: E/AndroidRuntime(30843): Caused by: android.view.InflateException: Binary XML file line #45: Error inflating class fragment
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
03-30 21:59:30.385: E/AndroidRuntime(30843): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.app.Activity.setContentView(Activity.java:1956)
03-30 21:59:30.385: E/AndroidRuntime(30843): at com.example.prototype.MainActivity.onCreate(MainActivity.java:88)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.app.Activity.performCreate(Activity.java:5372)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
03-30 21:59:30.385: E/AndroidRuntime(30843): ... 11 more
03-30 21:59:30.385: E/AndroidRuntime(30843): Caused by: java.lang.NullPointerException
03-30 21:59:30.385: E/AndroidRuntime(30843): at com.example.prototype.CurrentBookingFragment.onCreateView(CurrentBookingFragment.java:49)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.app.Fragment.performCreateView(Fragment.java:1699)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:879)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1053)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1155)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.app.Activity.onCreateView(Activity.java:4966)
03-30 21:59:30.385: E/AndroidRuntime(30843): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
03-30 21:59:30.385: E/AndroidRuntime(30843): ... 21 more
Creating the fragment:
Fragment CurrentBookingFragment;
CurrentBookingFragment = new CurrentBookingFragment();
FragmentManager fm = getFragmentManager();
Bundle bundle=new Bundle();
bundle.putString("GetStringPUFirstLine", "GetStringPUFirstLine");
CurrentBookingFragment.setArguments(bundle);
FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.BookingFragment, CurrentBookingFragment);
fragmentTransaction.commit();
Try setting the text in onActivityCreated(){}.
#Override
public void onActivityCreated(Bundle savedInstanceState)
{
TextView CurrentBookingFragmentTV = (TextView)view.findViewById(R.id.CurrentBookingFragmentTV);
CurrentBookingFragmentTV.setText(strtext);
}

Categories