2013-02-15 4 views
0

여기에 비슷한 질문이 많지만이 문제를 해결하는 데 도움을 준 사람은 아무도 없습니다.double 값 textview

메인 메뉴, 대시 보드 레이아웃이 있고 버튼이 4 개 있다고 가정 해 보겠습니다. A, B, C, D

내가 A를 누르면, 새로운 활동 A가 시작됩니다.이 활동 A에는 json 항목을 가져 오는 링크가 있습니다. 정상적인 URL로 잘 작동하지만 iam이 edit-text/textview에서 값을 가져 오려고 할 때 충돌이 발생합니다.

String url = "http://webservice.xxx.com/webservice/getLocationList.php?lat="+ latValue +"&lng="+ lngValue +""; 

latValuelngValueR.id.test 여기에 편집 상자에서 글고

에 대한 XML 파일 여기
<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/test" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

<EditText 
    android:id="@+id/latValue" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:inputType="numberDecimal" 
    android:text="54.9933628" > 

    <requestFocus /> 
</EditText> 

<EditText 
    android:id="@+id/lngValue" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="9.8595655" 
    android:inputType="numberDecimal" /> 
    </LinearLayout> 

그리고 나는 그것의 가치를 원하는이다 그것을 링크에 넣으십시오.

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


        EditText lat_source = (EditText)findViewById(R.id.latValue); 
here crash --> Double sourceLat = Double.parseDouble(lat_source.getText().toString()); 


    EditText lng_source = (EditText)findViewById(R.id.lngValue); 
    Double sourceLng = Double.parseDouble(lng_source.getText().toString()); 


    String url = "http://webservice.xxx.com/webservice/getLocationList.php?lat="+ sourceLat +"&lng="+ sourceLng +""; 

    Log.d(TAG, "My URL is = " + url); 

로그 setContentView을 통해, findViewById 통해 EditText 객체를 얻기 위해,보기가보기 계층 구조에 추가되어야 언급 한 바와 같이

02-15 11:37:41.826: E/AndroidRuntime(14267): at android.os.Looper.loop(Looper.java:137) 
    02-15 11:37:41.826: E/AndroidRuntime(14267): at android.app.ActivityThread.main(ActivityThread.java:4898) 
    02-15 11:37:41.826: E/AndroidRuntime(14267): at java.lang.reflect.Method.invokeNative(Native Method) 
    02-15 11:37:41.826: E/AndroidRuntime(14267): at java.lang.reflect.Method.invoke(Method.java:511) 
    02-15 11:37:41.826: E/AndroidRuntime(14267): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 
    02-15 11:37:41.826: E/AndroidRuntime(14267): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 
    02-15 11:37:41.826: E/AndroidRuntime(14267): at dalvik.system.NativeStart.main(Native Method) 
    02-15 11:37:41.826: E/AndroidRuntime(14267): Caused by: java.lang.NullPointerException 
    02-15 11:37:41.826: E/AndroidRuntime(14267): at com.androidhive.jsonparsing.LocationBased.onCreate(LocationBased.java:69) 
    02-15 11:37:41.826: E/AndroidRuntime(14267): at android.app.Activity.performCreate(Activity.java:5206) 
    02-15 11:37:41.826: E/AndroidRuntime(14267): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083) 
    02-15 11:37:41.826: E/AndroidRuntime(14267): at android.app.ActivityThread.performLaunchActivity 
+2

은 R.layout입니다. 두 개의 편집 텍스트가 포함 된 기본 레이아웃? – Blackbelt

+0

변경 double에서 double 데이터 유형. – rajeshwaran

+0

URL을 문자열로 직접 전달하기 위해 double을 변환하는 용도는 무엇입니까? –

답변

1
LayoutInflater inflater = LayoutInflater.from(this); 
LinearLayout testLayout = (LinearLayout)inflater.inflate(R.layout.test, null) 
EditText lat_source = (EditText)testLayout.findViewById(R.id.latValue); 
Double sourceLat = Double.parseDouble(lat_source.getText().toString()); 

, 또는 당신이 사용할 수있는 인플레이터를 사용하고 인플레이레이터가 반환 한 뷰의 객체를 사용하여 EditText

+0

대단히 고맙습니다. @blackbelt 역시 그렇게 생각한 것처럼 작동합니다. 나는이 팽창기 물건에 대해 안다. 그러나 지금 나는 해결을 가지고있다. 그리고 나는 무엇이 계속하고 있는지에 관해 안다. – Tirolel

+0

당신은 환영합니다 – Blackbelt