2011-11-29 4 views
0

그냥 웹 사이트에 브라우저를 여는 작은 안드로이드 애플 리케이션을 개발하려고합니다. Mac OS 10.6 및 최신 안드로이드/이클립스 도구를 사용하고 있습니다.왜이 예외 : java.lang.RuntimeException : 오류 inflating 클래스

11-29 13 : 03 : 55.113 : E/AndroidRuntime (1012) : java.lang.RuntimeException가 : 활동을 시작할 수 없습니다 ComponentInfo {com.mycomp/com.mycomp.pack 그러나 나는이 예외가 계속 } : android.view.InflateException : 바이너리 XML 파일 라인 # 7 : 오류 팽창 클래스 com.mycomp.MyTextView 여기

내 코드는 다음과 같습니다

package com.mycomp; 
import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.AttributeSet; 
import android.util.Log; 
import android.view.View; 
import android.widget.TextView; 


public class myapp extends Activity { 
/** Called when the activity is first created. */` 

private MyTextView myview; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main);  
    Log.d("onCreate", "onCreate "); 

    myview = (MyTextView)findViewById(R.id.myview); 
    myview.setParent(this); 
} 




public static class MyTextView extends TextView { 
    private View mLastVisChangedView; 
    private int mLastChangedVisibility; 
    private Activity parent; 

    public void setParent(Activity p){ 
     parent =p; 

    } 
    public MyTextView(Context context) { 
     super(context); 
    } 

    public MyTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public MyTextView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public View getLastVisChangedView() { 
     return mLastVisChangedView; 
    } 

    public int getLastChangedVisibility() { 
     return mLastChangedVisibility; 
    } 

    @Override 
    protected void onVisibilityChanged(View changedView, int visibility){ 
     Log.d("onVisibilityChanged", "new vis == " + visibility); 
     if (parent !=null && visibility == View.VISIBLE){ 
      parent.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mysite.com"))); 
      parent.moveTaskToBack(true); 
     } 
    } 
} 

} 

<?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" > 

<com.mycomp.MyTextView 
    android:id="@+id/myview" 
     android:text="@string/hello"/> 

</LinearLayout> 

답변

1

유형은 com.mycomp.myapp.MyTextView 될 것이다. (또는 $ 그것은 내부 클래스 이후?)

또한 다음과 같이 뷰를 지정해야 할 수도 있습니다 :

<view class="com.mycomp.myapp$MyEditText" ... 

나는 당신이이 경우에 onFinishInflate 필요하다고 생각하지 않습니다.

+0

감사합니다. 나는 그것을 시도했지만 $가있는 점으로. 이것은 나를 미치게했다. 다른 사람을위한 BTW, 그 후 나는 아직도 안드로이드를 추가 할 필요가 : layout_width = .. XML. –

+0

@Calgacus 문제 없음 :) 나는 그렇게 할 논리적 인 이유가 있다면 클래스를 중첩시킬 것입니다.하지만 하나는있을 수 있습니다. –

0

MyTextView 클래스는 별도의 파일에 저장해야합니다. 그러면 com.mycomp.MyTextView이 정확합니다.