2013-10-14 4 views
1

책에서 안드로이드 용 응용 프로그램을 개발하는 방법을 배우고 지침을 따른 후에 다음으로 끝납니다. 앱을 실행하면 setStartUpScreenText() 개체의 텍스트가 표시되지 않습니다.텍스트를 TextView로 설정할 수 없습니다.

MainActivity.java :

<TextView 
     android:id="@+id/DataView1" 
     android:layout_toRightOf="@+id/TextView1" 
     android:layout_marginLeft="36dip" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
+0

: (Apress의 90 페이지, 안드로이드 앱 개발, 출판사 알아보기) 이봐, 너의 활동 수업을 여기에 게시해라. –

답변

0

은 화면의 모든보기를 업데이트하기 전에 setContentView 메소드를 호출해야합니다

MainActivity.xml.

0

모든의

+0

어리 석고 나는 그것을 잊어 버렸다. 그러나 내가 실행하고 실행하려고 시도한 후에 오류가 발생했습니다 (불행히도 Hellow_World는 작동을 멈췄습니다.) 코드는 이전에 작동했지만 일부 텍스트는 누락되었습니다. –

0

주먹 setStartUpWorldValues() 기능의 내부 (시작 또는 끝 부분의 하나)에서 setStartUpScreenText() 함수를 호출 활동에서 OnCreate에서 setContentViewsetStartupScreenText() 메소드를 호출해야합니다. setStartUpWorldValues() 함수 뒤에 onCreate() 메서드 내에서이 함수를 호출 할 수도 있습니다.

가 두 번째로 다음 코드로 setStartUpScreenText() 함수의 전체 코드 교체 :

  TextView planetNameValue = (TextView) findViewById(R.id.dataView1); 
    planetNameValue.setText(earth.planetName); 
    TextView planetMassValue = (TextView) findViewById(R.id.dataView2); 
    planetMassValue.setText(String.valueOf(earth.planetMass)); 
    TextView planetGravityValue = (TextView) findViewById(R.id.dataView3); 
    planetGravityValue.setText(String.valueOf(earth.planetGravity)); 
    TextView planetColoniesValue = (TextView) findViewById(R.id.dataView4); 
    planetColoniesValue.setText(String.valueOf(earth.planetColonies)); 
    TextView planetPopulationValue = (TextView) findViewById(R.id.dataView5); 
    planetPopulationValue.setText(String.valueOf(earth.planetPopulation)); 
    TextView planetMilitaryValue = (TextView) findViewById(R.id.dataView6); 
    planetMilitaryValue.setText(String.valueOf(earth.planetMilitary)); 
    TextView planetBaseValue = (TextView) findViewById(R.id.dataView7); 
    planetBaseValue.setText(String.valueOf(earth.planetBases)); 
    TextView planetForceFieldValue = (TextView) findViewById(R.id.dataView8); 
    planetForceFieldValue.setText(String.valueOf(earth.planetProtection)); 
-1

보호 무효 setStartUpWorldValues ​​() {

earth.setPlanetColonies(1); //Set planet colonies to 1 
    earth.setPlanetMilitary(1); // set planet military to 1 
    earth.setColonyImmigration(1000); // set planet population to 1000 
    earth.setBaseProtection(100); // set Planet armed force to 100 
    earth.turnForceFieldOn(); // Turn on the planet force field 

setStartUpScreenText() ; 
    TextView planetNameValue = (TextView)findViewById(R.id.dataView1); 
    planetNameValue.setText(earth.planetName); 
    TextView planetMassValue = (TextView)findViewById(R.id.dataView2); 
    planetMassValue.setText(String.valueOf(earth.planetMass)); 
    TextView planetGravityValue = (TextView)findViewById(R.id.dataView3); 
    planetGravityValue.setText(String.valueOf(earth.planetGravity)); 
    TextView planetColoniesValue = (TextView)findViewById(R.id.dataView4); 
    planetColoniesValue.setText(String.valueOf(earth.planetColonies)); 
    TextView planetPopulationValue = (TextView)findViewById(R.id.dataView5); 
    planetPopulationValue.setText(String.valueOf(earth.planetPopulation)); 
    TextView planetMilitaryValue = (TextView)findViewById(R.id.dataView6); 
    planetMilitaryValue.setText(String.valueOf(earth.planetMilitary)); 
    TextView planetBasesValue = (TextView)findViewById(R.id.dataView7); 
    planetBasesValue.setText(String.valueOf(earth.planetBases)); 
    TextView planetForceFieldValue = (TextView)findViewById(R.id.dataView8); 
    planetForceFieldValue.setText(String.valueOf(earth.planetProtection));  
} 
private void setStartUpScreenText() { 
    // TODO Auto-generated method stub 

} 
관련 문제