错误:无法实例化类

时间:2012-04-27 10:05:51

标签: android android-layout

我从另一个项目复制了一些java和XML文件(因为我的朋友做了布局,但我做了核心编码,我们在不同的项目中做了)

不知怎的,当我实现我的代码的布局时,它给出了错误(类无法实例化),我修复了所有的包路径,刷新它,清理它,确保构造函数是公共的(显然),但是XML仍然给我错误。

该项目在我重启我的eclipse之后运行良好,它在没有任何失败的情况下运行并且在logcat中没有错误,但是当我在我的eclipse文件中检查friend_schedule.xml文件时它仍然给我错误,但它仍然给了我好奇如果以后会有任何影响,任何想法?

这是无法实例化的java文件:

package cal.endar;
public class FriendSchedule extends LinearLayout 
{
public FriendSchedule(Context con)
{
    super(con);
    initComponent(con);
}

public FriendSchedule(Context con, AttributeSet att)
{
    super(con, att);
    initComponent(con);
}

public void initComponent(Context con)
{
    LayoutInflater inf=LayoutInflater.from(con);
    View v=inf.inflate(R.layout.main, null,false);

    //View v=inf.inflate(R.layout.daily_layout, null,false);
    //View v=inf.inflate(R.layout.weekly_layout, null,false);
    addView(v);
    v.getLayoutParams().height=LayoutParams.MATCH_PARENT;
    LinearLayout.LayoutParams lp=(LinearLayout.LayoutParams) v.getLayoutParams();
    lp.weight=1;
}

public void onClick(View v)
{
    v.setBackgroundResource(R.drawable.app_list_selected);
}
}

这是我的friend_schedule.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_weight="0.13"
        android:gravity="left|center"
        android:text="My Name"
        android:textAppearance="?android:attr/textAppearanceLarge" />
 </LinearLayout>

<cal.endar.FriendSchedule
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:layout_weight="1"/>

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

我再次重启了我的日食,项目设法运行良好,没有任何错误(我不知道为什么会发生这种情况,我没有任何明确的答案)

但无论如何,感谢您的回复...