마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

버튼클릭시 다음화면과 링크하기에서 오류좀 찾아주세요. [closed]

0 추천

제가 Unfortunately, has stopped 때문에..하루종일 머리 싸매고 있는데 오류를 못찾겠습니다..

제 부족함을 탓해야죠. 혹시 아래 코드에서 에러발생요인을 아시면 적어주세요.

부탁드립니다.

FirstActivity.java

---------------------------------------------------------------------------------------

package com.example.libraryinfoapps;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class FirstActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);

Button button=(Button)findViewById(R.id.first_btn);
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v){
Toast.makeText(getApplicationContext(),"액티비티 전환" ,Toast.LENGTH_LONG).show();

Intent intent=new Intent(getApplicationContext(), SecondActivity.class);
startActivity(intent);
}
});

-----------------------------------------------------------------------------------

SecondActivity.java
-----------------------------------------------------------------------------------


package com.example.libraryinfoapps;

import android.app.Activity;
import android.os.Bundle;

public class SecondActivity extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
// TODO Auto-generated method stub
}

}
---------------------------------------------------------------------------------------

activity_first.xml

---------------------------------------------------------------------------------------

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/first_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="let's START"
android:textSize="15sp"
/>
< /LinearLayout>

---------------------------------------------------------------------------------------

activity_second.xml

---------------------------------------------------------------------------------------

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<textView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="두번째화면"
android:textSize="15sp"
/>

</LinearLayout>

대체 무슨오류인지 모르겠습니다.

질문을 종료한 이유: 답을 찾았습니다
haaa (170 포인트) 님이 2014년 5월 7일 질문
haaa님이 2014년 5월 14일 closed

4개의 답변

+1 추천

Toast.makeText(getApplicationContext(),"액티비티 전환" ,Toast.LENGTH_LONG).show();

 

내부 클래스에서 정의할땐

getApplicationContext() 가 아니라 (부모클래스).this 라고 정확히 명시해줘야하는것 아닌가요?

로그캣 내용이 있다면 더 좋을텐데...ㅋㅋ

안드로이드로우 (15,740 포인트) 님이 2014년 5월 13일 답변
0 추천
AndroidManifest.xml 에 세컨드 액티비티를 추가하셨는지 궁금하네요 'ㅅ'
초보개발자ㅠ (33,870 포인트) 님이 2014년 5월 7일 답변
추가 했습니다ㅠㅠ....
0 추천

Intent intent=new Intent(getApplicationContext(), SecondActivity.class);

Intent intent=new Intent(this, SecondActivity.class);

로 바꾸세요. menifest에 SecondActivity가 등록되어있는지도 보시고요.

코딩인헬 (12,150 포인트) 님이 2014년 5월 14일 답변
신경써주셔서 감사합니다~ 다른곳에서 답을 찾았어요^^
0 추천

AndroidManifest.xml 랑 로그캣 공개해주세요.

uno (3,820 포인트) 님이 2014년 5월 14일 답변
신경써주셔서 감사합니다~ 다른곳에서 답을 찾았어요^^
...