[android-developers] Android SSL Socket problem

2010-04-26 Thread David Arm
Hi all, im developing an android aplication and im facing some
problems with SSL. I tested the SSL communication between my server
and a java client at it works without problems, and now im having
problems trying to code an android client.

I imported my truststore on res/raw folder and so on, but the main
problem (even if i read the API) is that I dont know how to create the
sockets to comunicate with the server using that keystore. For example
I tried this:

 InputStream mIS =
context.getResources().openRawResource(R.raw.truststoreclient);

   keyStore = KeyStore.getInstance(BKS);
   keyStore.load(mIS, aquabona.toCharArray());


mKMF = KeyManagerFactory.getInstance(X509);
mKMF.init(keyStore,
truststoreclient.toCharArray());
KeyManager[] mKM = mKMF.getKeyManagers();
SSLContext sc = SSLContext.getInstance(TLS);
TrustManagerFactory tmf =
TrustManagerFactory.getInstance(X509);
tmf.init(keyStore);
sc.init(mKM, tmf.getTrustManagers(), new
java.security.SecureRandom());

SSLSocketFactory sslsocketfactory = new
SSLSocketFactory(keyStore);

   //Si hacemos la consulta a un unico servidor
   if (ips.size()  2  ipPorts.size()  2) {


   String singleServer = ips.get(0);
   int singlePort = 
Integer.parseInt(ipPorts.get(0));

   Socket soc = sslsocketfactory.createSocket();

   HttpParams params = new  BasicHttpParams();
   HttpProtocolParams.setVersion(params,
HttpVersion.HTTP_1_1);
   HttpProtocolParams.setContentCharset(params, 
utf-8);
   
params.setBooleanParameter(http.protocol.expect-
continue, false);

   Socket socket = 
sslsocketfactory.connectSocket(soc,
singleServer, singlePort, null, 0, params);

And now im having problems with certificates...

So is there an easier way to code up a SSL socket implementation on
android that uses that keystore?
Post some code, examples or ideas please.

Thanks all.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Listview and autocomplete problems!

2010-03-04 Thread David Arm
Hi all!

Im trying to fill an autocompletetextview with data that i retrieve
from a database, so the next time we do a search that data will be in
the autocompletetextview suggestions.

The problem is that, I can view the listView associated with the
autocompletetextview (and it retrieves the data from the database
without any problem), but if i click on a single element of the
textview instead of having the string I picked on the autocomplete
textview I have an string like sql.cur...@

I dont have any problems with the database as I followed the notepad
tutorial and it works well.

Thank you all and here is the code:


Java class:

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import android.app.Activity;
import android.app.ListActivity;
import android.content.ContentResolver;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Contacts;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.TextView;

import android.widget.SimpleCursorAdapter;
import android.database.Cursor;

//antes extends activity
public class RemoteIR extends ListActivity implements OnClickListener{

static String ipquery;
static String ipadress;
static int ipport;

protected static final String RESULTS=results;

@SuppressWarnings(unchecked)
ArrayList dataSend;
int noSend;
int startIndex =0;
int count = 100;

//antes textview
AutoCompleteTextView adress;
TextView port;
TextView query;
Button search, exit;

private int mDataNumber = 1;
private RemoteIrDbAdapter mDbHelper; //= null;


@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

mDbHelper = new RemoteIrDbAdapter(this);
mDbHelper.open();

//antes TextView
adress = (AutoCompleteTextView)this.findViewById(R.id.adress);


SimpleCursorAdapter notes = fillData();
adress.setAdapter(notes);



port = (TextView)this.findViewById(R.id.port);
query = (TextView)this.findViewById(R.id.query);

search = (Button)this.findViewById(R.id.search);
search.setOnClickListener(this);

exit = (Button)this.findViewById(R.id.exit);
exit.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {

finish();
}
});

}

@SuppressWarnings({ unchecked })
public void onClick(View v) {

ipquery = query.getText().toString();
ipadress = adress.getText().toString();

ipport = Integer.parseInt(port.getText().toString());

java.util.Date tempDate = new Date();
String date = tempDate.toString();

mDbHelper.createQueryData(ipadress, date);
fillData();
mDbHelper.close();

Log.d(RemoteIR, creamos cliente);

Client results;
Thread cThread = new Thread(results = new Client(startIndex,
count));

Log.d(RemoteIR, arrancamos cliente);

cThread.start();

try {
cThread.join();

ArrayList finalResults = results.getResults();

int finalNo = finalResults.size();

Intent intent = new Intent();

intent.setClass(RemoteIR.this, DisplayResult.class);

dataSend = finalResults;
noSend = finalNo;

int startIndex = 0;
int endIndex = 10; //ANTES 9

ActivitySwitchInfo asi = new ActivitySwitchInfo(dataSend,
noSend, startIndex, endIndex);

intent.putExtra(RESULTS, asi);

startActivity(intent);

finish();

 }
 catch (InterruptedException e) {
Log.e(RemoteIR, Join interrupted, e);
 }

}


 private void createData() {
String queryDataName = QueryData  + mDataNumber++;

mDbHelper.createQueryData(queryDataName,);
fillData();
}


private SimpleCursorAdapter fillData() {
Cursor c = mDbHelper.fetchAllQueryData();
startManagingCursor(c);
String[] from = new String[] { RemoteIrDbAdapter.KEY_QUERY};
int[] to = new int[] { R.id.row1 };

SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.query_row, c, from,
to);


return notes;
//setListAdapter(notes);
}


}


XML files:

?xml version=1.0 encoding=utf-8?
RelativeLayout
android:id=@+id/widget28
android:layout_width=fill_parent
android:layout_height=fill_parent
xmlns:android=http://schemas.android.com/apk/res/android;

LinearLayout
android:id=@+id/widget29
android:layout_width=250px
android:layout_height=180px

[android-developers] Re: Dynamic TableLayout problem

2010-02-03 Thread David Arm
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 emez...@gmail.com 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 zash...@gmail.com wrote:

  No idea? :s

  On 1 feb, 22:09, David Arm zash...@gmail.com wrote:

   Sorry, double post.

   On 1 feb, 18:37, David Arm zash...@gmail.com 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]
?xml version=1.0 encoding=utf-8?
TableLayout xmlns:android=http://schemas.android.com/apk/res/
android
   android:id=@+id/DisplayResults
   android:layout_width=fill_parent
   android:layout_height=fill_parent
   

   TableRow
       TextView
           android:layout_column=1
           android:text=Title
           android:padding=3dip /
       TextView
           android:text=Author
           android:padding=3dip /
       TextView
           android:text=File
           android:padding=3dip /
       TextView

[android-developers] Vertical scrollview disappears on vertical and horizontal scrollview scheme

2010-02-03 Thread David Arm
Hi! I´m just trying to have both vertical and horizontal scrollviews
but the vertical one disappears just 1 second after the app launch and
I cant scroll down on my results.

Here are the codes:


XML:

?xml version=1.0 encoding=utf-8?
ScrollView android:id=@+id/ScrollView
xmlns:android=http://schemas.android.com/apk/res/android;
android:layout_width=wrap_content
android:layout_height=wrap_content
android:scrollbars=vertical 

 HorizontalScrollView xmlns:android=http://schemas.android.com/apk/
res/android
android:id=@+id/HorizontalScrollView
android:layout_width=wrap_content
android:layout_height=wrap_content

TableLayout xmlns:android=http://schemas.android.com/apk/res/
android
android:id=@+id/DisplayResults
android:layout_width=fill_parent
android:layout_height=fill_parent




TableRow
  

TextView
android:layout_column=1
android:text=Title
android:padding=3dip /
TextView
android:layout_column=2
android:text=Author
android:padding=3dip/
TextView
android:layout_column=3
android:text=File
android:padding=3dip/
TextView
android:layout_column=4
android:text=ModDate
android:padding=3dip/
TextView
android:layout_column=5
android:text=Size
android:padding=3dip/
/TableRow


/TableLayout

/HorizontalScrollView


/ScrollView

JAVA:


package citic.android.remoteir;

import java.util.ArrayList;
import java.util.Iterator;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TableRow.LayoutParams;

import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.view.View;
import android.view.ViewGroup;

import android.widget.TableRow;
import android.widget.TextView;
import android.app.Activity;


public class DisplayResult extends Activity{


private boolean mShrink;

@SuppressWarnings(unchecked)
protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.displayresults);
Bundle extras = getIntent().getExtras();




final TableLayout tl = (TableLayout)findViewById
(R.id.DisplayResults);




//ArrayList finalResults;

if(extras!=null){

appendRow(tl, extras);

}

}




private void appendRow(TableLayout table, Bundle extras) {

ArrayList finalResults;

finalResults = (ArrayList) (extras.getSerializable
(RemoteIR.RESULTS));

Iterator it = finalResults.iterator();

while(it.hasNext()) {
SearchResult result = ((SearchResult) it.next());


TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(
   LayoutParams.FILL_PARENT,
   LayoutParams.WRAP_CONTENT));

TextView title = new TextView(this);
title.setText(result.title);
title.setPadding(3, 3, 3, 3);

TextView author = new TextView(this);
author.setText(result.author.toString());
author.setPadding(3, 3, 3, 3);

TextView file = new TextView(this);
file.setText(result.file.toString());

TextView modDate = new TextView(this);
modDate.setText(result.modDate);

TextView size = new TextView(this);
size.setText(result.size.toString());


 tr.addView(title, new TableRow.LayoutParams(1));
 tr.addView(author, new TableRow.LayoutParams());
 tr.addView(file, new TableRow.LayoutParams());
 tr.addView(modDate, new TableRow.LayoutParams());
 tr.addView(size, new TableRow.LayoutParams());


 table.addView(tr,new TableLayout.LayoutParams(
 LayoutParams.FILL_PARENT,
 LayoutParams.WRAP_CONTENT));

}

}


Thank you!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Dynamic TableLayout problem

2010-02-02 Thread David Arm
No idea? :s

On 1 feb, 22:09, David Arm zash...@gmail.com wrote:
 Sorry, double post.

 On 1 feb, 18:37, David Arm zash...@gmail.com 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]
  ?xml version=1.0 encoding=utf-8?
  TableLayout xmlns:android=http://schemas.android.com/apk/res/
  android
     android:id=@+id/DisplayResults
     android:layout_width=fill_parent
     android:layout_height=fill_parent
     

     TableRow
         TextView
             android:layout_column=1
             android:text=Title
             android:padding=3dip /
         TextView
             android:text=Author
             android:padding=3dip /
         TextView
             android:text=File
             android:padding=3dip /
         TextView
             android:text=ModDate
             android:padding=3dip /
         TextView
             android:text=Size
             android:padding=3dip /
     /TableRow

  /TableLayout[/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

[android-developers] Dynamic TableLayout problem

2010-02-01 Thread David Arm
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:


[code]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));

}

}


}

}[/code]

This is the xml:


[code]?xml version=1.0 encoding=utf-8?
TableLayout xmlns:android=http://schemas.android.com/apk/res/
android
android:id=@+id/DisplayResults
android:layout_width=fill_parent
android:layout_height=fill_parent


TableRow
TextView
android:layout_column=1
android:text=Title
android:padding=3dip /
TextView
android:text=Author
android:padding=3dip /
TextView
android:text=File
android:padding=3dip /
TextView
android:text=ModDate
android:padding=3dip /
TextView
android:text=Size
android:padding=3dip /
/TableRow


/TableLayout[/code]


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.149: ERROR/AndroidRuntime(938): at
android.app.ActivityThread.access$2200(ActivityThread.java:119)
02-01 12:10:34.149: ERROR/AndroidRuntime(938): at

[android-developers] Dynamic TableLayout problem

2010-02-01 Thread David Arm
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]
?xml version=1.0 encoding=utf-8?
TableLayout xmlns:android=http://schemas.android.com/apk/res/
android
   android:id=@+id/DisplayResults
   android:layout_width=fill_parent
   android:layout_height=fill_parent
   

   TableRow
   TextView
   android:layout_column=1
   android:text=Title
   android:padding=3dip /
   TextView
   android:text=Author
   android:padding=3dip /
   TextView
   android:text=File
   android:padding=3dip /
   TextView
   android:text=ModDate
   android:padding=3dip /
   TextView
   android:text=Size
   android:padding=3dip /
   /TableRow


/TableLayout[/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.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 

[android-developers] Re: Dynamic TableLayout problem

2010-02-01 Thread David Arm
Sorry, double post.

On 1 feb, 18:37, David Arm zash...@gmail.com 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]
 ?xml version=1.0 encoding=utf-8?
 TableLayout xmlns:android=http://schemas.android.com/apk/res/
 android
    android:id=@+id/DisplayResults
    android:layout_width=fill_parent
    android:layout_height=fill_parent
    

    TableRow
        TextView
            android:layout_column=1
            android:text=Title
            android:padding=3dip /
        TextView
            android:text=Author
            android:padding=3dip /
        TextView
            android:text=File
            android:padding=3dip /
        TextView
            android:text=ModDate
            android:padding=3dip /
        TextView
            android:text=Size
            android:padding=3dip /
    /TableRow

 /TableLayout[/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.149: ERROR/AndroidRuntime(938