Intent를 사용해서 상하위 액티브스를 사용 하려고 하는데요.
디버그를 사용 할때는 아래와 같은 메세지가 뜨고 버튼을 누르면 다시 또 뜨고
그냥 실행시켰을때에는 시작전에는 안뜨고 버튼을 누르면 아래 메세지가 뜨네요..
책이랑 인터넷을 다 찾아봤지만...DDMS로 확인했을때도 확실 이유를 못찾겠네요..
R.ID 값이 틀릴때 나온다고 하는데...ID 값도 다 확인해봤구요..
혹시 무엇이 잘못된 걸까요?
혹시 사진이 안 보이시면, 밑에 파일 첨부 해놨습니다.
package kr.co.test;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
public class test extends Activity implements OnClickListener{
/** Called when the activity is first created. */
private Intent AddActivity;
private Intent OrderActivity;
private Intent ProferencesActivity;
private Intent ReserventionActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT );
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
AddActivity = new Intent(test.this, Add.class);
OrderActivity = new Intent(test.this, Order.class);
ProferencesActivity = new Intent(test.this, Proferences.class);
ReserventionActivity = new Intent(test.this, Reservention.class);
AddActivity.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
OrderActivity.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
ProferencesActivity.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
ReserventionActivity.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Button cAddBtn = (Button)findViewById(R.id.addBtn);
Button cOrderBtn = (Button)findViewById(R.id.orderBtn);
Button cProferencesBtn = (Button)findViewById(R.id.proferencesBtn);
Button cReserventionBtn = (Button)findViewById(R.id.reserventionBtn);
cAddBtn.setOnClickListener(this);
cOrderBtn.setOnClickListener(this);
cProferencesBtn.setOnClickListener(this);
cReserventionBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.addBtn:
startActivity(AddActivity);
break;
case R.id.orderBtn:
startActivity(OrderActivity);
break;
case R.id.proferencesBtn:
startActivity(ProferencesActivity);
break;
case R.id.reserventionBtn:
startActivity(ReserventionActivity);
break;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/str_main_title"
/>
<Button
android:layout_height="wrap_content"
android:id="@+id/orderBtn"
android:text="@string/str_main_order"
android:layout_width="fill_parent"
/>
<Button
android:layout_height="wrap_content"
android:id="@+id/approvalBtn"
android:text="@string/str_main_order"
android:layout_width="fill_parent"
/>
<Button
android:id="@+id/addBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/str_main_addcard"
/>
<Button
android:id="@+id/reserventionBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/str_main_reservention"
/>
<Button
android:id="@+id/proferencesBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/str_main_proferences"
/>
</LinearLayout>




만약 NullPointer 예외라면 main.xml에 존재하는 버튼에 android:id 속성값을 확인해 봐야 할 것 같습니다.