[android-developers] Re: Dynamic TableLayout problem
Ok, solved y just have to use final on the tablelayout statement. If someone wants the code ill post it. Thanks for your reply Beth. On 2 feb, 18:13, Beth wrote: > David, > The output shows you have a null pointer at line 93 of your activity. > Look there for a solution. > Also, I noticed you have System.out.println. Where are you expecting > the println output to appear? You might want to replace that with > Android.util.log. > Regards, > Beth > > On Feb 2, 3:41 am, David Arm wrote: > > > No idea? :s > > > On 1 feb, 22:09, David Arm wrote: > > > > Sorry, double post. > > > > On 1 feb, 18:37, David Arm wrote: > > > > > 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="java"]import java.util.ArrayList; > > > > > import android.app.Activity; > > > > import android.content.Intent; > > > > import android.os.Bundle; > > > > import android.util.Log; > > > > import android.view.View; > > > > import android.view.View.OnClickListener; > > > > import android.widget.Button; > > > > import android.widget.TextView; > > > > > public class DisplayResult extends Activity{ > > > > > /** Called when the activity is first created. */ > > > > > �...@suppresswarnings("unchecked") > > > > public void onCreate(Bundle savedInstanceState) { > > > > > System.out.println("2º actividad lanzada"); > > > > > super.onCreate(savedInstanceState); > > > > setContentView(R.layout.displayresults); > > > > Bundle extras = getIntent().getExtras(); > > > > > //this.setContentView(R.layout.main); > > > > > /* Find Tablelayout defined in main.xml */ > > > > TableLayout tl = (TableLayout)findViewById > > > > (R.layout.displayresults); > > > > > ArrayList finalResults; > > > > > if(extras!=null){ > > > > finalResults = (ArrayList) (extras.getSerializable > > > > (RemoteIR.RESULTS)); > > > > > Iterator it = finalResults.iterator(); > > > > > while(it.hasNext()) { > > > > SearchResult result = ((SearchResult) it.next()); > > > > > /* Create a new row to be added. */ > > > > TableRow tr = new TableRow(this); > > > > tr.setLayoutParams(new LayoutParams( > > > > LayoutParams.FILL_PARENT, > > > > LayoutParams.WRAP_CONTENT)); > > > > > TextView title = new TextView(this); > > > > title.setText(result.title.toString()); > > > > //System.out.println(title.getText()); > > > > > TextView author = new TextView(this); > > > > author.setText(result.author.toString()); > > > > > TextView file = new TextView(this); > > > > file.setText(result.file.toString()); > > > > > TextView modDate = new TextView(this); > > > > author.setText(result.modDate.toString()); > > > > > TextView size = new TextView(this); > > > > size.setText(result.size.toString()); > > > > > title.setLayoutParams(new LayoutParams( > > > > LayoutParams.FILL_PARENT, > > > > LayoutParams.WRAP_CONTENT)); > > > > > author.setLayoutParams(new LayoutParams( > > > > LayoutParams.FILL_PARENT, > > > > LayoutParams.WRAP_CONTENT)); > > > > > file.setLayoutParams(new LayoutParams( > > > > LayoutParams.FILL_PARENT, > > > > LayoutParams.WRAP_CONTENT)); > > > > > modDate.setLayoutParams(new LayoutParams( > > > > LayoutParams.FILL_PARENT, > > > > LayoutParams.WRAP_CONTENT)); > > > > > size.setLayoutParams(new LayoutParams( > > > > LayoutParams.FILL_PARENT, > > > > LayoutParams.WRAP_CONTENT)); > > > > > tr.addView(title); > > > > tr.addView(author); > > > > tr.addView(file); > > > > tr.addView(modDate); > > > > tr.addView(size); > > > > > tl.addView(tr,new TableLayout.LayoutParams( > > > > LayoutParams.FILL_PARENT, > > > > LayoutParams.WRAP_CONTENT)); > > > > > } > > > > > } > > > > > } > > > > > }[/syntax] > > > > > This is the xml: > > > > > [syntax="xml"] > > > > > > > > http://schemas.android.com/apk/res/ > > > > android" > > > > android:id="@+id/DisplayResults" > > > > android:layout_width="fill_parent" > > > > android:layout_height="fill_parent" > > > > > > > > > > > > > > > > > android:layout_column="1" > > > >
[android-developers] Re: Dynamic TableLayout problem
David, The output shows you have a null pointer at line 93 of your activity. Look there for a solution. Also, I noticed you have System.out.println. Where are you expecting the println output to appear? You might want to replace that with Android.util.log. Regards, Beth On Feb 2, 3:41 am, David Arm wrote: > No idea? :s > > On 1 feb, 22:09, David Arm wrote: > > > Sorry, double post. > > > On 1 feb, 18:37, David Arm wrote: > > > > 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="java"]import java.util.ArrayList; > > > > import android.app.Activity; > > > import android.content.Intent; > > > import android.os.Bundle; > > > import android.util.Log; > > > import android.view.View; > > > import android.view.View.OnClickListener; > > > import android.widget.Button; > > > import android.widget.TextView; > > > > public class DisplayResult extends Activity{ > > > > /** Called when the activity is first created. */ > > > > �...@suppresswarnings("unchecked") > > > public void onCreate(Bundle savedInstanceState) { > > > > System.out.println("2º actividad lanzada"); > > > > super.onCreate(savedInstanceState); > > > setContentView(R.layout.displayresults); > > > Bundle extras = getIntent().getExtras(); > > > > //this.setContentView(R.layout.main); > > > > /* Find Tablelayout defined in main.xml */ > > > TableLayout tl = (TableLayout)findViewById > > > (R.layout.displayresults); > > > > ArrayList finalResults; > > > > if(extras!=null){ > > > finalResults = (ArrayList) (extras.getSerializable > > > (RemoteIR.RESULTS)); > > > > Iterator it = finalResults.iterator(); > > > > while(it.hasNext()) { > > > SearchResult result = ((SearchResult) it.next()); > > > > /* Create a new row to be added. */ > > > TableRow tr = new TableRow(this); > > > tr.setLayoutParams(new LayoutParams( > > > LayoutParams.FILL_PARENT, > > > LayoutParams.WRAP_CONTENT)); > > > > TextView title = new TextView(this); > > > title.setText(result.title.toString()); > > > //System.out.println(title.getText()); > > > > TextView author = new TextView(this); > > > author.setText(result.author.toString()); > > > > TextView file = new TextView(this); > > > file.setText(result.file.toString()); > > > > TextView modDate = new TextView(this); > > > author.setText(result.modDate.toString()); > > > > TextView size = new TextView(this); > > > size.setText(result.size.toString()); > > > > title.setLayoutParams(new LayoutParams( > > > LayoutParams.FILL_PARENT, > > > LayoutParams.WRAP_CONTENT)); > > > > author.setLayoutParams(new LayoutParams( > > > LayoutParams.FILL_PARENT, > > > LayoutParams.WRAP_CONTENT)); > > > > file.setLayoutParams(new LayoutParams( > > > LayoutParams.FILL_PARENT, > > > LayoutParams.WRAP_CONTENT)); > > > > modDate.setLayoutParams(new LayoutParams( > > > LayoutParams.FILL_PARENT, > > > LayoutParams.WRAP_CONTENT)); > > > > size.setLayoutParams(new LayoutParams( > > > LayoutParams.FILL_PARENT, > > > LayoutParams.WRAP_CONTENT)); > > > > tr.addView(title); > > > tr.addView(author); > > > tr.addView(file); > > > tr.addView(modDate); > > > tr.addView(size); > > > > tl.addView(tr,new TableLayout.LayoutParams( > > > LayoutParams.FILL_PARENT, > > > LayoutParams.WRAP_CONTENT)); > > > > } > > > > } > > > > } > > > > }[/syntax] > > > > This is the xml: > > > > [syntax="xml"] > > > > > > http://schemas.android.com/apk/res/ > > > android" > > > android:id="@+id/DisplayResults" > > > android:layout_width="fill_parent" > > > android:layout_height="fill_parent" > > > > > > > > > > > > > android:layout_column="1" > > > android:text="Title" > > > android:padding="3dip" /> > > > > > android:text="Author" > > > android:padding="3dip" /> > > > > > android:text="File" > > > android:padding="3dip" /> > > > > > android:text="ModDate" > > > android:padding="3dip" /> > > > > >
[android-developers] Re: Dynamic TableLayout problem
No idea? :s On 1 feb, 22:09, David Arm wrote: > Sorry, double post. > > On 1 feb, 18:37, David Arm wrote: > > > 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="java"]import java.util.ArrayList; > > > import android.app.Activity; > > import android.content.Intent; > > import android.os.Bundle; > > import android.util.Log; > > import android.view.View; > > import android.view.View.OnClickListener; > > import android.widget.Button; > > import android.widget.TextView; > > > public class DisplayResult extends Activity{ > > > /** Called when the activity is first created. */ > > > �...@suppresswarnings("unchecked") > > public void onCreate(Bundle savedInstanceState) { > > > System.out.println("2º actividad lanzada"); > > > super.onCreate(savedInstanceState); > > setContentView(R.layout.displayresults); > > Bundle extras = getIntent().getExtras(); > > > //this.setContentView(R.layout.main); > > > /* Find Tablelayout defined in main.xml */ > > TableLayout tl = (TableLayout)findViewById > > (R.layout.displayresults); > > > ArrayList finalResults; > > > if(extras!=null){ > > finalResults = (ArrayList) (extras.getSerializable > > (RemoteIR.RESULTS)); > > > Iterator it = finalResults.iterator(); > > > while(it.hasNext()) { > > SearchResult result = ((SearchResult) it.next()); > > > /* Create a new row to be added. */ > > TableRow tr = new TableRow(this); > > tr.setLayoutParams(new LayoutParams( > > LayoutParams.FILL_PARENT, > > LayoutParams.WRAP_CONTENT)); > > > TextView title = new TextView(this); > > title.setText(result.title.toString()); > > //System.out.println(title.getText()); > > > TextView author = new TextView(this); > > author.setText(result.author.toString()); > > > TextView file = new TextView(this); > > file.setText(result.file.toString()); > > > TextView modDate = new TextView(this); > > author.setText(result.modDate.toString()); > > > TextView size = new TextView(this); > > size.setText(result.size.toString()); > > > title.setLayoutParams(new LayoutParams( > > LayoutParams.FILL_PARENT, > > LayoutParams.WRAP_CONTENT)); > > > author.setLayoutParams(new LayoutParams( > > LayoutParams.FILL_PARENT, > > LayoutParams.WRAP_CONTENT)); > > > file.setLayoutParams(new LayoutParams( > > LayoutParams.FILL_PARENT, > > LayoutParams.WRAP_CONTENT)); > > > modDate.setLayoutParams(new LayoutParams( > > LayoutParams.FILL_PARENT, > > LayoutParams.WRAP_CONTENT)); > > > size.setLayoutParams(new LayoutParams( > > LayoutParams.FILL_PARENT, > > LayoutParams.WRAP_CONTENT)); > > > tr.addView(title); > > tr.addView(author); > > tr.addView(file); > > tr.addView(modDate); > > tr.addView(size); > > > tl.addView(tr,new TableLayout.LayoutParams( > > LayoutParams.FILL_PARENT, > > LayoutParams.WRAP_CONTENT)); > > > } > > > } > > > } > > > }[/syntax] > > > This is the xml: > > > [syntax="xml"] > > > > http://schemas.android.com/apk/res/ > > android" > > android:id="@+id/DisplayResults" > > android:layout_width="fill_parent" > > android:layout_height="fill_parent" > > > > > > > > > android:layout_column="1" > > android:text="Title" > > android:padding="3dip" /> > > > android:text="Author" > > android:padding="3dip" /> > > > android:text="File" > > android:padding="3dip" /> > > > android:text="ModDate" > > android:padding="3dip" /> > > > android:text="Size" > > android:padding="3dip" /> > > > > > [/syntax] > > > 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): [b] > > java.lang.RuntimeException: Unable to start activity ComponentInfo > > {citic.android.remoteir/citic.android.remoteir.DisplayResult}: > > java.lang.NullPointerException[/b] > > 02-01
[android-developers] Re: Dynamic TableLayout problem
Sorry, double post. On 1 feb, 18:37, David Arm wrote: > 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="java"]import java.util.ArrayList; > > import android.app.Activity; > import android.content.Intent; > import android.os.Bundle; > import android.util.Log; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.Button; > import android.widget.TextView; > > public class DisplayResult extends Activity{ > > /** Called when the activity is first created. */ > > �...@suppresswarnings("unchecked") > public void onCreate(Bundle savedInstanceState) { > > System.out.println("2º actividad lanzada"); > > super.onCreate(savedInstanceState); > setContentView(R.layout.displayresults); > Bundle extras = getIntent().getExtras(); > > //this.setContentView(R.layout.main); > > /* Find Tablelayout defined in main.xml */ > TableLayout tl = (TableLayout)findViewById > (R.layout.displayresults); > > ArrayList finalResults; > > if(extras!=null){ > finalResults = (ArrayList) (extras.getSerializable > (RemoteIR.RESULTS)); > > Iterator it = finalResults.iterator(); > > while(it.hasNext()) { > SearchResult result = ((SearchResult) it.next()); > > /* Create a new row to be added. */ > TableRow tr = new TableRow(this); > tr.setLayoutParams(new LayoutParams( > LayoutParams.FILL_PARENT, > LayoutParams.WRAP_CONTENT)); > > TextView title = new TextView(this); > title.setText(result.title.toString()); > //System.out.println(title.getText()); > > TextView author = new TextView(this); > author.setText(result.author.toString()); > > TextView file = new TextView(this); > file.setText(result.file.toString()); > > TextView modDate = new TextView(this); > author.setText(result.modDate.toString()); > > TextView size = new TextView(this); > size.setText(result.size.toString()); > > title.setLayoutParams(new LayoutParams( > LayoutParams.FILL_PARENT, > LayoutParams.WRAP_CONTENT)); > > author.setLayoutParams(new LayoutParams( > LayoutParams.FILL_PARENT, > LayoutParams.WRAP_CONTENT)); > > file.setLayoutParams(new LayoutParams( > LayoutParams.FILL_PARENT, > LayoutParams.WRAP_CONTENT)); > > modDate.setLayoutParams(new LayoutParams( > LayoutParams.FILL_PARENT, > LayoutParams.WRAP_CONTENT)); > > size.setLayoutParams(new LayoutParams( > LayoutParams.FILL_PARENT, > LayoutParams.WRAP_CONTENT)); > > tr.addView(title); > tr.addView(author); > tr.addView(file); > tr.addView(modDate); > tr.addView(size); > > tl.addView(tr,new TableLayout.LayoutParams( > LayoutParams.FILL_PARENT, > LayoutParams.WRAP_CONTENT)); > > } > > } > > } > > }[/syntax] > > This is the xml: > > [syntax="xml"] > > http://schemas.android.com/apk/res/ > android" > android:id="@+id/DisplayResults" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > > > > > android:layout_column="1" > android:text="Title" > android:padding="3dip" /> > android:text="Author" > android:padding="3dip" /> > android:text="File" > android:padding="3dip" /> > android:text="ModDate" > android:padding="3dip" /> > android:text="Size" > android:padding="3dip" /> > > > [/syntax] > > 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): [b] > java.lang.RuntimeException: Unable to start activity ComponentInfo > {citic.android.remoteir/citic.android.remoteir.DisplayResult}: > java.lang.NullPointerException[/b] > 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.