onClickCreateButton을 클릭 할 때마다 다음과 같이 반환됩니다. android.content.res.Resources $ NotFoundException : 문자열 리소스 ID # 0x1
주요 활동 클래스는 다음과 같습니다.
public class MainActivity extends AppCompatActivity {
EditText mInput;
RelativeLayout.LayoutParams layoutParams;
LinearLayout linearLayout2;
LinearLayout linearLayout3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInput = findViewById(R.id.EditText);
linearLayout2 = findViewById(R.id.LinearLayout2);
layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
linearLayout3 = new LinearLayout(this);
linearLayout3.setLayoutParams(layoutParams);
linearLayout3.setOrientation(LinearLayout.HORIZONTAL);
linearLayout2.addView(linearLayout3);
}
public void onClickCreateButton(View v) {
LinearLayout temp;
try {
Toast.makeText(getApplicationContext(), linearLayout2.getChildCount(), Toast.LENGTH_SHORT).show();
if (linearLayout2.getChildCount() <= 8) {
temp = (LinearLayout) linearLayout2.getChildAt(linearLayout2.getChildCount());
Toast.makeText(getApplicationContext(), temp.getChildCount(), Toast.LENGTH_SHORT).show();
if (temp.getChildCount() <= 3) {
Button button = new Button(this);
button.setText(mInput.getText().toString());
button.setLayoutParams(layoutParams);
linearLayout3.addView(button);
} else {
linearLayout3 = new LinearLayout(this);
linearLayout3.setLayoutParams(layoutParams);
linearLayout3.setOrientation(LinearLayout.HORIZONTAL);
linearLayout2.addView(linearLayout3);
}
}
} catch (Exception ex)
{
Toast.makeText(getApplicationContext(), ex+"", Toast.LENGTH_SHORT).show();
}
}
activity_main :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
</LinearLayout>
누군가가 내 코드의 실수를 지적 할 수 있다면 큰 도움이 될 것입니다. 감사! 건배!
Toast.makeText(getApplicationContext(), temp.getChildCount(), Toast.LENGTH_SHORT).show();
temp.getChildCount()
를 반환하고 인수를 int
받는 Toast.makeText()
오버로드 int
는 리소스 ID가 될 것으로 예상합니다. String
대신에 int
를 문자열 로 변환 하여 오버로드를 사용하십시오.
Toast.makeText(getApplicationContext(), "" + temp.getChildCount(), Toast.LENGTH_SHORT).show();
다른 Toast
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다