当我打开此页面时,应用程序意外停止,没有微调器选项没有问题但是当我添加它们时应用程序崩溃...
logcat text http://pastebin.com/umKP8iD0
package com.calc;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Button;
import android.widget.TimePicker;
import android.view.View;
public class setup extends Activity
{
TextView start, end;
TimePicker startTime, endTime;
Spinner day;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
String dayText[] = new String[6];
start = (TextView) findViewById(R.id.textView1);
end = (TextView) findViewById(R.id.textView2);
startTime = (TimePicker) findViewById(R.id.timePicker1);
endTime = (TimePicker) findViewById(R.id.timePicker2);
day = (Spinner) findViewById(R.id.spinner1);
dayText[0] = "Sunday";
dayText[1] = "Monday";
dayText[2] = "Tuesday";
dayText[3] = "Wednesday";
dayText[4] = "Thursday";
dayText[5] = "Friday";
dayText[6] = "Saturday";
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, dayText);
day.setAdapter(adapter);
super.onCreate(savedInstanceState);
setContentView(R.layout.enterpage);
}
}
我想知道是不是因为旋转器我创造它错了?
答案 0 :(得分:1)
您必须先使用setContentView
才能获得查看ID ...
如果在设置视图之前尝试获取ID,它们将返回null,然后您将获得NPE问题。
移动它,这是第一个,你的应用程序应该工作。
修改
您也没有在阵列中设置足够的插槽。你需要6个插槽并尝试将7个项目放入其中。试试这个:
String daytext[] = new String[7];