TableLayout Problem! (Dynamic)

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

TableLayout Problem! (Dynamic)

Postby David » Mon Feb 01, 2010 4:55 pm

Hi! Im having a problem with a tablelayout. Im trying to add rows
dinamically and display the content of these rows (there are not
content problems as T tested it and the app has all the data that it
needs).

This is the java code and the xml of the activity:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import java.util.ArrayList;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.view.View.OnClickListener;
  9. import android.widget.Button;
  10. import android.widget.TextView;
  11.  
  12.  
  13. public class DisplayResult extends Activity{
  14.  
  15.        /** Called when the activity is first created. */
  16.  
  17.        @SuppressWarnings("unchecked")
  18.        public void onCreate(Bundle savedInstanceState) {
  19.  
  20.                System.out.println("2º actividad lanzada");
  21.  
  22.        super.onCreate(savedInstanceState);
  23.        setContentView(R.layout.displayresults);
  24.        Bundle extras = getIntent().getExtras();
  25.  
  26.  
  27.        //this.setContentView(R.layout.main);
  28.  
  29.    /* Find Tablelayout defined in main.xml */
  30.    TableLayout tl = (TableLayout)findViewById
  31. (R.layout.displayresults);
  32.  
  33.        ArrayList finalResults;
  34.  
  35.        if(extras!=null){
  36.                finalResults = (ArrayList) (extras.getSerializable
  37. (RemoteIR.RESULTS));
  38.  
  39.                Iterator it = finalResults.iterator();
  40.  
  41.                while(it.hasNext()) {
  42.                SearchResult result = ((SearchResult) it.next());
  43.  
  44.                /* Create a new row to be added. */
  45.        TableRow tr = new TableRow(this);
  46.        tr.setLayoutParams(new LayoutParams(
  47.                       LayoutParams.FILL_PARENT,
  48.                       LayoutParams.WRAP_CONTENT));
  49.  
  50.        TextView title = new TextView(this);
  51.                title.setText(result.title.toString());
  52.                //System.out.println(title.getText());
  53.  
  54.                TextView author = new TextView(this);
  55.                author.setText(result.author.toString());
  56.  
  57.                TextView file = new TextView(this);
  58.                file.setText(result.file.toString());
  59.  
  60.                TextView modDate = new TextView(this);
  61.                author.setText(result.modDate.toString());
  62.  
  63.                TextView size = new TextView(this);
  64.                size.setText(result.size.toString());
  65.  
  66.             title.setLayoutParams(new LayoutParams(
  67.                       LayoutParams.FILL_PARENT,
  68.                       LayoutParams.WRAP_CONTENT));
  69.  
  70.             author.setLayoutParams(new LayoutParams(
  71.                     LayoutParams.FILL_PARENT,
  72.                     LayoutParams.WRAP_CONTENT));
  73.  
  74.             file.setLayoutParams(new LayoutParams(
  75.                     LayoutParams.FILL_PARENT,
  76.                     LayoutParams.WRAP_CONTENT));
  77.  
  78.             modDate.setLayoutParams(new LayoutParams(
  79.                     LayoutParams.FILL_PARENT,
  80.                     LayoutParams.WRAP_CONTENT));
  81.  
  82.             size.setLayoutParams(new LayoutParams(
  83.                     LayoutParams.FILL_PARENT,
  84.                     LayoutParams.WRAP_CONTENT));
  85.  
  86.             tr.addView(title);
  87.             tr.addView(author);
  88.             tr.addView(file);
  89.             tr.addView(modDate);
  90.             tr.addView(size);
  91.  
  92.  
  93.            tl.addView(tr,new TableLayout.LayoutParams(
  94.                     LayoutParams.FILL_PARENT,
  95.                     LayoutParams.WRAP_CONTENT));
  96.  
  97.                                        }
  98.  
  99.                }
  100.  
  101.  
  102.        }
  103.  
  104. }
Parsed in 0.042 seconds, using GeSHi 1.0.8.4



This is the xml:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/
  3. android"
  4.   android:id="@+id/DisplayResults"
  5.   android:layout_width="fill_parent"
  6.   android:layout_height="fill_parent"
  7.   >
  8.  
  9.    <TableRow>
  10.        <TextView
  11.           android:layout_column="1"
  12.           android:text="Title"
  13.           android:padding="3dip" />
  14.        <TextView
  15.           android:text="Author"
  16.           android:padding="3dip" />
  17.        <TextView
  18.           android:text="File"
  19.           android:padding="3dip" />
  20.        <TextView
  21.           android:text="ModDate"
  22.           android:padding="3dip" />
  23.        <TextView
  24.           android:text="Size"
  25.           android:padding="3dip" />
  26.    </TableRow>
  27.  
  28.  
  29. </TableLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4



And this is the error that is frustrating me :s

ERROR:

02-01 12:10:34.129: ERROR/AndroidRuntime(938): Uncaught handler:
thread main exiting due to uncaught exception
02-01 12:10:34.149: ERROR/AndroidRuntime(938):
java.lang.RuntimeException: Unable to start activity ComponentInfo
{citic.android.remoteir/citic.android.remoteir.DisplayResult}:
java.lang.NullPointerException

02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2496)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2512)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
android.app.ActivityThread.access$2200(ActivityThread.java:119)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
android.os.Handler.dispatchMessage(Handler.java:99)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
android.os.Looper.loop(Looper.java:123)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
android.app.ActivityThread.main(ActivityThread.java:4363)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
java.lang.reflect.Method.invokeNative(Native Method)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
java.lang.reflect.Method.invoke(Method.java:521)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:860)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
dalvik.system.NativeStart.main(Native Method)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): Caused by:
java.lang.NullPointerException
[b]02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
citic.android.remoteir.DisplayResult.onCreate(DisplayResult.java:93)[/
b]
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2459)


Thank you all in advance! (I hope that someone helps me)
David
Freshman
Freshman
 
Posts: 5
Joined: Mon Feb 01, 2010 4:51 pm

Top

Postby David » Mon Feb 01, 2010 5:00 pm

And sorry about my english (most of my posts and threads are on local android sites).
David
Freshman
Freshman
 
Posts: 5
Joined: Mon Feb 01, 2010 4:51 pm

Postby David » Tue Feb 02, 2010 12:44 pm

No idea yet? :s
David
Freshman
Freshman
 
Posts: 5
Joined: Mon Feb 01, 2010 4:51 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests