2016-04-01 12 views
-3

ログイン活動をしようとしています 問題があります。私のセッターはうまく動作しません、なぜ私は知らないのですか? 私は3つのクラスを持っています。セッターは働いていません

第一1は、サーバーのデータとゲッターとセッター

したデータである私は、ログイン活動

public class Settings extends AppCompatActivity { 
//declarations 

//Edittext fields for username , server, password & port information 
EditText edtIpurl, edtPort, edtUsername, edtPassword; 
//Textviews that can be clicked 
TextView databaseDel, databaseRef, magnumgmbh, contact, support; 
//imagebuttons for bottom menu 
ImageButton contacts, articles, invoices, orders; 
//string for server URL 
//String sURL = "http://"; 
Thread newSettingsThread; 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_settings); 


    setTitle("Settings"); 

    newSettingsThread = new Thread(){ 
     public void run(){ 
      runOnUiThread(new Runnable() { 

       @Override 
       public void run() { 
        String serverURL = "http://rest.magnumgmbh.de"; 

        //edtIpurl = (EditText)findViewById(R.id.edtIpurl); 

        Data newD = new Data(); 
        newD.setServerURL(serverURL); 
       } 
      }); 
     } 
    }; 
    newSettingsThread.start(); 




    //start activitys if bottom buttons clicked 
    contacts = (ImageButton) findViewById(R.id.contacts); 

    //articles activity start 
    contacts.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      //start activity addresses 
      Intent startAddresses = new Intent(Settings.this, Addresses.class); 
      startActivity(startAddresses); 
     } 
    }); 
}} 

を開始し、私は私の新しいを取得しようとする場所を次のいずれかがある第二1である

public class Data{ 

String addressesURL = "/DataSnap/rest/TServerMethods1/LookupCustomers"; 
String articlesURL = "/DataSnap/rest/TServerMethods1/LookupArticle"; 
String invoicesURL = "/DataSnap/rest/TServerMethods1/LookupInvoice"; 
String invoicesDetailsURL = "/DataSnap/rest/TServerMethods1/LookupInvoicePos"; 
String invoicesDetailsAddressesURL = "/DataSnap/rest/TServerMethods1/LookupInvoiceAddress"; 
String ordersURL = "/DataSnap/rest/TServerMethods1/LookupOrders"; 
String ordersDetailsURL = "/DataSnap/rest/TServerMethods1/LookupOrdersPos"; 
String ordersDetailsAddressesURL = "/DataSnap/rest/TServerMethods1/LookupOrdersAddress"; 
public String serverURL; 
//String serverURL = "http://10.10.10.75:8081"; 
String username = "admin"; 
String password = "admin"; 


public String getPassword() { 
    return password; 
} 

public void setPassword(String password) { 
    this.password = password; 
} 

public String getUsername() { 
    return username; 
} 

public void setUsername(String username) { 
    this.username = username; 
} 

public String getAddressesURL() { 
    return addressesURL; 
} 

public void setAddressesURL(String addressesURL) { 
    this.addressesURL = addressesURL; 
} 

public String getArticlesURL() { 
    return articlesURL; 
} 

public void setArticlesURL(String articlesURL) { 
    this.articlesURL = articlesURL; 
} 

public String getInvoicesURL() { 
    return invoicesURL; 
} 

public void setInvoicesURL(String invoicesURL) { 
    this.invoicesURL = invoicesURL; 
} 

public String getInvoicesDetailsURL() { 
    return invoicesDetailsURL; 
} 

public void setInvoicesDetailsURL(String invoicesDetailsURL) { 
    this.invoicesDetailsURL = invoicesDetailsURL; 
} 

public String getInvoicesDetailsAddressesURL() { 
    return invoicesDetailsAddressesURL; 
} 

public void setInvoicesDetailsAddressesURL(String invoicesDetailsAddressesURL) { 
    this.invoicesDetailsAddressesURL = invoicesDetailsAddressesURL; 
} 

public String getOrdersURL() { 
    return ordersURL; 
} 

public void setOrdersURL(String ordersURL) { 
    this.ordersURL = ordersURL; 
} 

public String getOrdersDetailsURL() { 
    return ordersDetailsURL; 
} 

public void setOrdersDetailsURL(String ordersDetailsURL) { 
    this.ordersDetailsURL = ordersDetailsURL; 
} 

public String getOrdersDetailsAddressesURL() { 
    return ordersDetailsAddressesURL; 
} 

public void setOrdersDetailsAddressesURL(String ordersDetailsAddressesURL) { 
    this.ordersDetailsAddressesURL = ordersDetailsAddressesURL; 
} 

public String getServerURL() { 
    return serverURL; 
} 

public void setServerURL(String serverURL) { 
    this.serverURL = serverURL; 
}} 

serverURL

public class Address extends AppCompatActivity{ 
    Thread newAddressThread; 
    @Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_addresses); 

    //set activity name 
    setTitle("Addresses"); 

    //new thread for network operations 
    newAddressesThread = new Thread() { 
     public void run() { 
      //make text from json 
      jsonText = new StringBuilder(); 
      try { 
       String str; 
       Data newData = new Data(); 


       //json dates url 
       String addressesURL = newData.getAddressesURL(); 
       String serverUrl = newData.getServerURL(); 
       String username = newData.getUsername(); 
       String password = newData.getPassword(); 

       URL url = new URL(serverUrl + addressesURL); 
       HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); 
       //String encoded = Base64.encode("admin:admin"); 
       String encoded = Base64.encodeToString((username+":"+password).getBytes("UTF-8"), Base64.NO_WRAP); 
       urlConnection.setRequestProperty("Authorization", "Basic " + encoded); 

       //check http status code 
       try { 
        int statusCode = urlConnection.getResponseCode(); 
        System.out.println(statusCode); 
       } catch (IOException e) { 

       } 

       BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); 
       while ((str = in.readLine()) != null) { 
        jsonText.append(str); 
       } 
       //cast stringbuilder to string 
       addressesJsonStr = jsonText.toString(); 
       //close IOstream 
       in.close(); 
      } catch (MalformedURLException e1) { 
       System.out.println(e1.getMessage()); 
      } catch (IOException e) { 
       System.out.println(e.getMessage()); 
      } 
      } 
    }; 

    //start thread 
    newAddressesThread.start(); 
}} 

serverURLで3番目のHierにはnullがあります。"だから私の問題です。 どうすればいいですか?

+0

2つの異なるオブジェクト。値を1に設定し、もう一方から値を読み取ろうとしています。それはあなたがポストイットの住所を書き留めているようなものです。そして、そのポストイットをどこに残して帰宅しますか?自宅で別のポストイットを取って、そこにアドレスが書かれていると期待しています... – Fildor

答えて

0

3番目のクラスに新しいオブジェクトを作成しているため、2番目のクラスで設定したURLが別のオブジェクトに格納されているため、URLにinitilize値があります。

タイプデータのすべてのオブジェクトが同じアドレスを持つようにするには、変数を静的にします。それ以外の場合は、3番目のクラスの2番目のクラスで作成したオブジェクトにアクセスする必要があります。

関連する問題