프로페셔널 안드로이드 책 관련 소스 실행 오류 관련 문의 입니다.
내용은 이해가 가는데 실행하려니 에뮬레이터에서 오류가 나네요.
에뮬레이터 오류 내용은 캡쳐 화면으로 올립니다.
아래는 전체 소스 내용입니다
* 혹시 몰라서 프로젝트 파일은 압축해서 올립니다.
프로젝트명 : A1LayoutResource
패키지명 : com.paad.chapter4
////////////////////////////////////////////////////////////////////////
// 파일명 : A5CompoundControls.java
////////////////////////////////////////////////////////////////////////
/**
* Demonstrate the compound controls created in
* {@link ClearbleEditText} and {@link ClearableEditTextInCode}.
*/
package com.paad.chapter4;
import android.app.Activity;
import android.os.Bundle;
public class A5CompoundControls extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.compound_view_activity);
}
}
////////////////////////////////////////////////////////////////////////
// 파일명 : compound_view_activity.xml
////////////////////////////////////////////////////////////////////////
<?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">
<com.paad.chapter4.ClearableEditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<com.paad.chapter4.ClearableEditTextInCode
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
////////////////////////////////////////////////////////////////////////
// 파일명 : clearable_edit_text_view.xml
////////////////////////////////////////////////////////////////////////
<?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">
<EditText
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/clearButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Clear"
/>
</LinearLayout>
////////////////////////////////////////////////////////////////////////
// 파일명 : ClearableEditText.java
////////////////////////////////////////////////////////////////////////
/**
* Creating a new compound view by extending LinearLayout.
* In this example the layout itself is defined as an external
* resource {@link clearable_edit_text_view} which is inflated
* within the constructor.
*/
package com.paad.chapter4;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
public class ClearableEditText extends LinearLayout {
EditText editText;
Button clearButton;
public ClearableEditText(Context context) {
super(context);
// Get a reference to the LayoutInflater Service
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater)getContext().getSystemService(infService);
// Inflate the view from the layout resource
li.inflate(R.layout.clearable_edit_text_view, this, true);
// Get references to the child controls
editText = (EditText)findViewById(R.id.editText);
clearButton = (Button)findViewById(R.id.clearButton);
// Hook up the functionality
hookupButton();
}
private void hookupButton() {
clearButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
editText.setText("");
}
});
}
}
////////////////////////////////////////////////////////////////////////
// 파일명 : ClearableEditTextInCode.java
////////////////////////////////////////////////////////////////////////
/**
* Creating a new compound view be extending LinearLayout.
* In this example the layout is defined in code
* within the constructor.
*/
package com.paad.chapter4;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
public class ClearableEditTextInCode extends LinearLayout {
EditText editText;
Button clearButton;
public ClearableEditTextInCode(Context context) {
super(context);
// Set orientation of layout to vertical
setOrientation(LinearLayout.VERTICAL);
// Create the child controls.
editText = new EditText(getContext());
clearButton = new Button(getContext());
clearButton.setText("Clear");
// Lay them out in the compound control.
int lHeight = LayoutParams.WRAP_CONTENT;
int lWidth = LayoutParams.FILL_PARENT;
addView(editText, new LinearLayout.LayoutParams(lWidth, lHeight));
addView(clearButton, new LinearLayout.LayoutParams(lWidth, lHeight));
// Hook up the functionality
hookupButton();
}
private void hookupButton() {
clearButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
editText.setText("");
}
});
}
}
아래는 오류 화면입니다.
Logcat 오류 부분만 넣었습니다.
10-13 06:23:54.698: ERROR/AndroidRuntime(837): Uncaught handler: thread main exiting due to uncaught exception
10-13 06:23:54.737: ERROR/AndroidRuntime(837): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.paad.chapter4/com.paad.chapter4.A5CompoundControls}: android.view.InflateException: Binary XML file line #7: Error inflating class com.paad.chapter4.ClearableEditText
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.os.Handler.dispatchMessage(Handler.java:99)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.os.Looper.loop(Looper.java:123)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.app.ActivityThread.main(ActivityThread.java:4203)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at java.lang.reflect.Method.invokeNative(Native Method)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at java.lang.reflect.Method.invoke(Method.java:521)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at dalvik.system.NativeStart.main(Native Method)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.paad.chapter4.ClearableEditText
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.view.LayoutInflater.createView(LayoutInflater.java:502)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:564)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.app.Activity.setContentView(Activity.java:1620)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at com.paad.chapter4.A5CompoundControls.onCreate(A5CompoundControls.java:16)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): ... 11 more
10-13 06:23:54.737: ERROR/AndroidRuntime(837): Caused by: java.lang.NoSuchMethodException: ClearableEditText(Context,AttributeSet)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at java.lang.Class.getMatchingConstructor(Class.java:669)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at java.lang.Class.getConstructor(Class.java:484)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): at android.view.LayoutInflater.createView(LayoutInflater.java:474)
10-13 06:23:54.737: ERROR/AndroidRuntime(837): ... 21 more
10-13 06:23:54.776: ERROR/dalvikvm(837): Unable to open stack trace file '/data/anr/traces.txt': Permission denied