저는 안드로이드 프로그래밍에 익숙하지 않습니다. 버튼을 만든 프로그램을 작성했습니다 ... 다른 페이지로 이동해야하는 클릭을 클릭하십시오. 아무런 오류 메시지가 나타나지 않지만 애플리케이션을 실행하면 즉시 "불행히도 멈췄다"고 말하고 프로그램을 닫습니다. 안드로이드 앱이 안타깝게도 중지되었습니다
이
내 코드package com.hotel;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class HotelActivity extends Activity implements OnClickListener {
Button btnClick=null, button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hotel);
button1 = (Button)findViewById(R.id.button1);
btnClick.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_hotel, menu);
return true;
}
@Override
public void onClick(View v) {
if(R.id.button1==v.getId())
{
Intent i= new Intent(HotelActivity.this,MenuActivity.class);
startActivity(i);
}
// TODO Auto-generated method stub
}
}
이며,이는 repective XML 파일
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HotelActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="162dp"
android:text="@string/start" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
</RelativeLayout>
이것이 두 번째 페이지의 코드
package com.hotel;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;
@SuppressLint("ShowToast") public class MenuActivity extends Activity implements OnItemClickListener{
/** Called when the activity is first created. */
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
lv = (ListView)findViewById(R.id.menu_settings);
lv.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String selValue= (String)lv.getItemAtPosition(arg2);
Toast.makeText(getApplicationContext(), "Selected Item = "+selValue, 1000).show();
// TODO Auto-generated method stub
}
}
,
는이 우리는 더 나은 서비스를 도울 수 있도록 로그 캣 스택 추적을 필요로 각각의 XML 파일
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/courses">
</ListView>
</LinearLayout>
이클립스에서 logcat을 시작하거나, 터미널을 다운로드하거나 휴대 전화에 '로그 수집기'와 같은 앱을 다운로드하십시오. 무언가 충돌하면 로그가 생깁니다. 당신이 무엇을 잘못하고 있는지 말해 줄 것이 확실합니다. –
btnClick.setOnClickListener (this)를 button1.setOnClickListener (this)로 변경하면 .. 작동합니다 .. – ridoy