我正在尝试开发一个只需打开浏览器到网站的小型Android应用程序。我正在使用mac OS 10.6和最新的android / eclipse工具。但我一直得到这个例外:
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>
答案 0 :(得分:1)
类型为com.mycomp.myapp.MyTextView
。 (或$
,因为它是一个内部类?)
您可能还需要按如下方式指定视图:
<view class="com.mycomp.myapp$MyEditText" ...
在这种情况下,我认为你不需要onFinishInflate
。
答案 1 :(得分:0)
您应该将MyTextView
类放在单独的文件中。那么com.mycomp.MyTextView
就是正确的。