View from XML does not display

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

View from XML does not display

Postby Manfred » Thu Feb 12, 2009 1:46 pm

Hi!

I have a class that extends View, that i have declared in the xml-layout file.
The class has this constructor:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Gamefield extends View
  2.  
  3. {
  4.  
  5. ....
  6.  
  7.         public Gamefield(Context context, AttributeSet attrs)
  8.  
  9.         {
  10.  
  11.                 super(context, attrs);
  12.  
  13.                 this.ctx = context;
  14.  
  15.                
  16.  
  17.                 game = new Game();
  18.  
  19.                 neueRunde();
  20.  
  21.                 chip10 = this.getResources().getDrawable(R.drawable.chip_10);
  22.  
  23.                 chip10.setBounds(100,100,120,120);
  24.  
  25.                 chip50 = this.getResources().getDrawable(R.drawable.chip_50);
  26.  
  27.                 chip50.setBounds(100,100,120,120);
  28.  
  29.                 chip100 = this.getResources().getDrawable(R.drawable.chip_100);
  30.  
  31.                 chip100.setBounds(100,100,120,120);
  32.  
  33.                 chip500 = this.getResources().getDrawable(R.drawable.chip_500);
  34.  
  35.                 chip500.setBounds(100,100,120,120);
  36.  
  37.                
  38.  
  39.                 bank = (TextView) ((Activity)ctx).findViewById(R.id.TextViewBank);
  40.  
  41.                 bank.bringToFront();
  42.  
  43.                 punkte = (TextView) ((Activity)ctx).findViewById(R.id.TextViewPunkte);
  44.  
  45.                 punkte.bringToFront();
  46.  
  47.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


The XML-Layout file:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <AbsoluteLayout android:id="@+id/AbsoluteLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
  2.  
  3.  
  4.  
  5. <ListView android:id="@+id/android:list" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView>
  6.  
  7. <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/TextViewBank" android:layout_y="300px" android:layout_x="200px" android:text="Bank:"></TextView>
  8.  
  9. <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/TextViewPunkte" android:layout_x="5px" android:layout_y="300px" android:text="Player:" android:bufferType="normal"></TextView>
  10.  
  11. <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="100px" android:layout_y="120px" android:textSize="20px" android:id="@+id/TextViewMessage"></TextView>
  12.  
  13.  
  14.  
  15. <com.andriod.blackjack.Gamefield
  16.  
  17.          android:layout_width="wrap_content"
  18.  
  19.          android:layout_height="wrap_content"
  20.  
  21.          android:text="BJ"
  22.  
  23.          android:background="@string/backpic"/>
  24.  
  25. </AbsoluteLayout>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


So my question is, does this code create an Instance of the class Gamefield?? Because i need a reference to this class in my code and how do i get it?

Here the code where the layout is set
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class GameActivity extends ListActivity
  2.  
  3. {
  4.  
  5.         private static final int BET_ID = Menu.FIRST;
  6.  
  7.         private static final int EXIT_ID = Menu.FIRST+1;
  8.  
  9.         private static final int NEWCARD_ID = Menu.FIRST+2;
  10.  
  11.         private static final int SHOW_ID = Menu.FIRST+3;
  12.  
  13.         private static final int TAKEMONEY_ID = Menu.FIRST+4;
  14.  
  15.         private TextView message;
  16.  
  17.        
  18.  
  19.         private Gamefield gf;
  20.  
  21.        
  22.  
  23.     @Override
  24.  
  25.     public void onCreate(Bundle savedInstanceState)
  26.  
  27.     {
  28.  
  29.         super.onCreate(savedInstanceState);
  30.  
  31.         setContentView(R.layout.game);
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Thanks!
Manfred
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Feb 10, 2009 2:13 pm

Top

Postby Manfred » Thu Feb 12, 2009 3:14 pm

I have tried around and looked at the LunarLander example. Therefore i changed my XML to this:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3.  
  4.  
  5. <FrameLayout
  6.  
  7.         android:layout_width="wrap_content"
  8.  
  9.         android:layout_height="wrap_content"
  10.  
  11.         xmlns:android="http://schemas.android.com/apk/res/android">
  12.  
  13.  
  14.  
  15.         <com.andriod.blackjack.Gamefield
  16.  
  17.                   android:id="@+id/gf"
  18.  
  19.          android:layout_width="wrap_content"
  20.  
  21.          android:layout_height="wrap_content"
  22.  
  23.          android:background="@string/backpic"/>
  24.  
  25.          
  26.  
  27.     <RelativeLayout
  28.  
  29.        android:layout_width="fill_parent"
  30.  
  31.        android:layout_height="fill_parent" >
  32.  
  33.         <TextView
  34.  
  35.          android:id="@+id/TextViewBank"
  36.  
  37.                   android:text="Bank:"
  38.  
  39.                   android:visibility="visible"
  40.  
  41.          android:layout_width="wrap_content"
  42.  
  43.          android:layout_height="wrap_content"
  44.  
  45.          android:layout_centerInParent="true"
  46.  
  47.          android:gravity="center_horizontal"
  48.  
  49.          android:textColor="#88ffffff"
  50.  
  51.          android:textSize="10sp"/>
  52.  
  53.          
  54.  
  55.         <TextView
  56.  
  57.          android:id="@+id/TextViewPunkte"
  58.  
  59.                   android:text="Player:"
  60.  
  61.                   android:visibility="visible"
  62.  
  63.          android:layout_width="wrap_content"
  64.  
  65.          android:layout_height="wrap_content"
  66.  
  67.          android:layout_centerInParent="true"
  68.  
  69.          android:gravity="center_horizontal"
  70.  
  71.          android:textColor="#88ffffff"
  72.  
  73.          android:textSize="10sp"/>
  74.  
  75.          
  76.  
  77.         <TextView
  78.  
  79.          android:id="@+id/TextViewMessage"
  80.  
  81.                   android:text="Message"
  82.  
  83.                   android:visibility="visible"
  84.  
  85.          android:layout_width="wrap_content"
  86.  
  87.          android:layout_height="wrap_content"
  88.  
  89.          android:layout_centerInParent="true"
  90.  
  91.          android:gravity="center_horizontal"
  92.  
  93.          android:textColor="#88ffffff"
  94.  
  95.          android:textSize="10sp"/>
  96.  
  97.          
  98.  
  99.      </RelativeLayout>
  100.  
  101.      
  102.  
  103. </FrameLayout>
Parsed in 0.006 seconds, using GeSHi 1.0.8.4


The class GameActivity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public void onCreate(Bundle savedInstanceState)
  2.  
  3.     {
  4.  
  5.         super.onCreate(savedInstanceState);
  6.  
  7.         setContentView(R.layout.game);
  8.  
  9.         gf = (Gamefield) findViewById(R.id.gf);
  10.  
  11.        
  12.  
  13.         message = (TextView)this.findViewById(R.id.TextViewMessage);
  14.  
  15.  
  16.  
  17.         gf.setBackgroundDrawable(getResources().getDrawable(R.drawable.back));
  18.  
  19.         gf.neueRunde();
  20.  
  21.         //this.addContentView(gf, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  22.  
  23.        
  24.  
  25.     }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


But now i get this Error:
Binary XML file line #8: Error inflating class java.lang.reflect.Constructor
Manfred
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Feb 10, 2009 2:13 pm

Postby Manfred » Thu Feb 12, 2009 3:26 pm

Ok, i think i have fixed it, this Resource could not be found

android:background="@string/backpic"


I have deleted this line!
Manfred
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Feb 10, 2009 2:13 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests