두 가지 활동 사이를 탐색하려하지만 응용 프로그램이 충돌하고 강제 닫기를 요청합니다. 여기 활동 간 이동이 일어나지 않습니다.
내 코드입니다 : 1 활동public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
//public boolean returnFlag = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button YesButton = (Button) findViewById(R.id.button1);
YesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(view.getContext(),Activity2.class);
startActivity(myIntent);
finish();
}
});
}
2 활동 :
public class Activity2 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.answerspage);
Button butTryAgain = (Button) findViewById(R.id.id_tryagain);
butTryAgain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(view.getContext(), HelloWorldActivity.class);
startActivity(myIntent);
finish();
}
});
}
}
main.xml에 - HelloWorldActivity의
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"android:textAppearance="?
android:attr/textAppearanceLarge" android:id="@+id/textView1" `android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="27dp" android:text="Welcome"></TextView>`
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" `android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/textView2" android:text="Is your question ready??" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:layout_marginTop="29dp"></TextView>`
<Button android:text="Yes" android:layout_width="wrap_content" `android:layout_height="wrap_content" android:id="@+id/button1" android:layout_alignBaseline="@+id/button2" android:layout_alignBottom="@+id/button2" android:layout_alignLeft="@+id/textView2" android:layout_marginLeft="36dp"></Button>`
<Button android:text="No" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/button2" `android:layout_below="@+id/textView2" android:layout_alignRight="@+id/textView2" android:layout_marginRight="38dp" android:layout_marginTop="54dp"></Button>`
</RelativeLayout>
answerspage.xml - activity2에의 XML 파일
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/FrameLayout1" `xmlns:android="http://schemas.android.com/apk/res/android"`
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Try again" android:id="@+id/button1" `android:layout_alignBaseline="@+id/id_tryagain" android:layout_alignBottom="@+id/button2"` `android:layout_alignParentLeft="true" android:layout_marginLeft="68dp"></Button>`
<Button android:layout_height="wrap_content" android:text="Quit" `android:id="@+id/button2" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/id_quit" android:layout_marginLeft="29dp" android:layout_marginTop="127dp" android:layout_width="wrap_content"></Button>`
<TextView android:layout_width="wrap_content" `android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/textView1" android:text="TextView" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="46dp" android:editable="true"></TextView>`
</RelativeLayout>
이것은 온 클릭 방법에 내 Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.HelloWorld"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloWorldActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2"></activity>
</application>
</manifest>
I have gone through http://www.warriorpoint.com/blog/2009/05/24/android-how-to-switch-between-activities/ to implement the same
충돌에 대한 스택 추적을 보았습니까? Eclipse를 사용하는 경우 LogCat보기로 전환하고 충돌시 분출 된 스택 추적을 찾으십시오. 스택 트레이스를 이해할 수 없다면, 우리가 볼 수 있도록 여기에 게시하십시오. – glorifiedHacker
NullPointerException이 발생하고 스택 추적이 발생 함 예외 처리 비동기 스레드 큐 예외 처리 비동기 스레드 큐 org.eclipse.jdt.internal.debug.core.model.JDIObjectValue를 org.eclipse.jdt.debug로 형변환 할 수 없습니다. core.IJavaArray – captgeek029
아래의 두 가지 답변이 솔루션을 보유하지 않는 경우 (HelloWorldActivity에서 컨텍스트를 얻는 것이 옳다) LogCat에서 얻을 수있는만큼 스택 추적을 게시하십시오. NullPointerException의 소스는 스택 추적 어딘가에 묻힐 가능성이 큽니다. – glorifiedHacker