Can't append text in new Intent

Put your problem here if it does not fit any of the other categories.

Can't append text in new Intent

Postby gajozuhra4 » Mon Dec 21, 2009 6:27 pm

Hi,
I am working on a student project and i have to make an android based application that will connect on a server having mysql databse(using servlets), and this server has automatic response on every update of database. I made standalone non android application in java and it works fine. When i use this code, adapted for android, to run on android emulator i can't see these results on new intent layout. I am using 2 intents, the first, starting intent, executes mysql query and it calls second intent that has a simple EditText compomnent and I want to see results in that second component. The problem is when second intent is started there is only black screen.

Here is the code of the first Intent:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import android.app.Activity;
  3.  
  4. import android.os.Bundle;
  5.  
  6. import android.view.View;
  7.  
  8. import android.view.View.OnClickListener;
  9.  
  10. import android.widget.*;
  11.  
  12. import android.content.Intent; // postavljanje Intenta
  13.  
  14. import android.net.Uri; // parsiranje URI-a
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. public class projekt extends Activity implements OnClickListener {
  25.  
  26.        
  27.  
  28.        
  29.  
  30.         private CheckBox prvi;
  31.  
  32.         private CheckBox drugi;
  33.  
  34.         private Button gumb;
  35.  
  36.         static public String url;
  37.  
  38.        
  39.  
  40.  
  41.  
  42.     public void onCreate(Bundle savedInstanceState) {
  43.  
  44.         super.onCreate(savedInstanceState);
  45.  
  46.         setContentView(R.layout.main);
  47.  
  48.        
  49.  
  50.        prvi =  (CheckBox) findViewById(R.id.prvi);
  51.  
  52.        drugi =  (CheckBox) findViewById(R.id.drugi);
  53.  
  54.        gumb = (Button) findViewById(R.id.gumb);
  55.  
  56.      gumb.setOnClickListener(this);
  57.  
  58.  
  59.  
  60.        
  61.  
  62.     }
  63.  
  64.    
  65.  
  66.        public void onClick(View v) {
  67.  
  68.         if(v == gumb) {
  69.  
  70.             url = upit(prvi,drugi);
  71.  
  72.                        
  73.  
  74.         Intent prozor = new Intent (this,prozor.class);
  75.  
  76.        
  77.  
  78.            prozor.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
  79.  
  80.            prozor.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  81.  
  82.        
  83.  
  84.            
  85.  
  86.            startActivity(prozor); }
  87.  
  88.        
  89.  
  90.        }
  91.  
  92.        
  93.  
  94.        public String upit (CheckBox prvi, CheckBox drugi) {
  95.  
  96.            
  97.  
  98.            if(prvi.isChecked() && drugi.isChecked()) {
  99.  
  100.                    
  101.  
  102.                    return "select%*%from%tablica" ;
  103.  
  104.                    
  105.  
  106.            } else if (prvi.isChecked())  return "select%ime%from%tablica";
  107.  
  108.            
  109.  
  110.            else if(drugi.isChecked()) return  "select%prezime%from%tablica";
  111.  
  112.            else return "ERROR!!";
  113.  
  114.        
  115.  
  116.                
  117.  
  118.        
  119.  
  120.     }
  121.  
  122. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Here is the code of second intent:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. import java.io.BufferedReader;
  5.  
  6. import java.io.BufferedWriter;
  7.  
  8. import java.io.FileWriter;
  9.  
  10. import java.io.IOException;
  11.  
  12. import java.io.InputStreamReader;
  13.  
  14. import java.net.HttpURLConnection;
  15.  
  16. import java.net.MalformedURLException;
  17.  
  18. import java.net.URL;
  19.  
  20. import android.app.Activity;
  21.  
  22. import android.content.Context;
  23.  
  24. import android.content.Intent;
  25.  
  26. import android.os.Bundle;
  27.  
  28. import android.os.PowerManager;
  29.  
  30. import android.os.PowerManager.WakeLock;
  31.  
  32. import android.widget.*;
  33.  
  34. import java.io.*;
  35.  
  36. import org.xml.sax.SAXException;
  37.  
  38. import org.xml.sax.XMLReader;
  39.  
  40. import java.io.FileOutputStream;
  41.  
  42. import java.io.OutputStreamWriter;
  43.  
  44. import javax.xml.parsers.SAXParser;
  45.  
  46. import javax.xml.parsers.SAXParserFactory;
  47.  
  48.  
  49.  
  50.  
  51.  
  52. public class prozor extends Activity {
  53.  
  54.        
  55.  
  56.        
  57.  
  58.         private int id=0;
  59.  
  60.         private EditText prikaz;
  61.  
  62.         private FileOutputStream fOut = null;
  63.  
  64.         private String path_local = "/data/data/projekt.android/files/bogovski.xml";
  65.  
  66.           String adresa = projekt.url;
  67.  
  68.        
  69.  
  70.         public static StringBuffer parsbuf = new StringBuffer();;
  71.  
  72.        
  73.  
  74.        
  75.  
  76.        
  77.  
  78.        
  79.  
  80.    public void onCreate(Bundle savedInstanceState) {
  81.  
  82.                 super.onCreate(savedInstanceState);
  83.  
  84.                
  85.  
  86.                 setContentView(R.layout.prozor);
  87.  
  88.                
  89.  
  90.                
  91.  
  92.                 prikaz = (EditText) findViewById(R.id.tekst);
  93.  
  94.                  prikaz.append("....");  //-----------------------------------------------------------------TESTING SECOND INTENT
  95.  
  96.                                         prvakonekcija(adresa,id);
  97.  
  98.                
  99.  
  100.                        
  101.  
  102.                 }
  103.  
  104.                
  105.  
  106.                
  107.  
  108.                
  109.  
  110.                        
  111.  
  112.                        
  113.  
  114.                        
  115.  
  116.  
  117.  
  118.          
  119.  
  120.                
  121.  
  122.  
  123.  
  124.  
  125.  
  126. public void prvakonekcija(String address,int id) {
  127.  
  128.        
  129.  
  130.         URL page;
  131.  
  132.         String line;
  133.  
  134.         StringBuffer text = new StringBuffer();
  135.  
  136.        
  137.  
  138.         try {
  139.  
  140.                
  141.  
  142.                 page = new URL("SERVER_URL_GOES_HERE"+projekt.url);
  143.  
  144.                        
  145.  
  146.      try {
  147.  
  148.          HttpURLConnection konekcija1 = (HttpURLConnection) page.openConnection();
  149.  
  150.          konekcija1.connect();
  151.  
  152.          
  153.  
  154.              
  155.  
  156.          
  157.  
  158.          BufferedReader in1 = new BufferedReader(
  159.  
  160.                                 new InputStreamReader(
  161.  
  162.                                 konekcija1.getInputStream()));
  163.  
  164.    
  165.  
  166.                  
  167.  
  168.          do {
  169.  
  170.                
  171.  
  172.              line = in1.readLine();
  173.  
  174.              if(line == null) break;
  175.  
  176.              text.append(line + "\n");
  177.  
  178.          } while (line != null);
  179.  
  180.      
  181.  
  182.          
  183.  
  184.       try {
  185.  
  186.                  
  187.  
  188.           BufferedWriter out = new BufferedWriter(new FileWriter(path_local));
  189.  
  190.           out.write(text.toString());
  191.  
  192.           out.close();
  193.  
  194.              
  195.  
  196.                      
  197.  
  198.       } catch (IOException e) {
  199.  
  200.           System.out.println(e.getMessage());
  201.  
  202.       }
  203.  
  204.  
  205.  
  206.  
  207.  
  208.            
  209.  
  210.       SAXParserFactory spf = SAXParserFactory.newInstance();
  211.  
  212.       SAXParser sp = spf.newSAXParser();
  213.  
  214.       XMLReader xr = sp.getXMLReader();
  215.  
  216.       Parser handler = new Parser(id);
  217.  
  218.           xr.setContentHandler(handler);
  219.  
  220.           xr.setErrorHandler(handler);
  221.  
  222.           sp.parse(new File(path_local), handler);
  223.  
  224.          
  225.  
  226.       System.out.println(parsbuf.toString());
  227.  
  228.       prikaz.append(parsbuf.toString());
  229.  
  230.      
  231.  
  232.  
  233.  
  234.      URL page1 = new URL("SERVER_URL_GOES_HERE");
  235.  
  236.      HttpURLConnection konekcija2 = (HttpURLConnection) page1.openConnection();
  237.  
  238.      konekcija2.connect();
  239.  
  240.      
  241.  
  242.      
  243.  
  244.       BufferedReader in2 = new BufferedReader(
  245.  
  246.                                 new InputStreamReader(
  247.  
  248.                                 konekcija2.getInputStream()));
  249.  
  250.              
  251.  
  252.      
  253.  
  254.       do {
  255.  
  256.            line = in2.readLine();
  257.  
  258.          } while (line == null);
  259.  
  260.      
  261.  
  262.      
  263.  
  264.       konekcija2.disconnect();
  265.  
  266.       konekcija1.disconnect();
  267.  
  268.       int salji = Integer.parseInt(line);
  269.  
  270.       prvakonekcija(adresa,salji);
  271.  
  272.          
  273.  
  274.                
  275.  
  276.      } catch (IOException ioe) {         
  277.  
  278.      System.out.println(ioe.getMessage());    
  279.  
  280.      
  281.  
  282.      } catch (SAXException e) {        
  283.  
  284.          System.out.println(e.getMessage());
  285.  
  286.          
  287.  
  288.         } catch (Exception e) {        
  289.  
  290.                  System.out.println(e.getMessage());
  291.  
  292.         }
  293.  
  294.  
  295.  
  296.         } catch (MalformedURLException e) {    
  297.  
  298.                  System.out.println(e.getMessage());
  299.  
  300.                  }
  301.  
  302.        
  303.  
  304.         }
  305.  
  306. }
  307.  
  308.  
Parsed in 0.047 seconds, using GeSHi 1.0.8.4


I have a parser class that parses the xml and second intent is using this class i have added in my project. The code that is commented as "testing second intent" in onCreate method of second intent is shown only when i comment out the next line of code (calling of function prvakonekcija(adresa,id);). It is interesting that application works with System.out.println and results can be seen in Logcat, but when i try to append it on EditText component nothing is happening (only black screen). In attachment there is a snippet of logcat. In red circle you can see correct application results that I want to see on second Intent. Maybe the line in blue square (in Logcat) is causing problems?!?

Thank you in advance for your time
Attachments
logcat.JPG
logcat.JPG (59.85 KiB) Viewed 324 times
gajozuhra4
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Dec 21, 2009 5:18 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests