2012-04-27 91 views
0

我從另一個項目複製了一些Java和XML文件(因爲我的朋友做了佈局,但我做的核心編碼,我們在不同的項目做)錯誤:類不能被實例化

不知怎的,當我實現佈局到我的代碼給它的錯誤(類無法實例化),我修復了所有的包路徑,刷新它,清理它,確保構造函數是public(顯然),但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> 
+0

您可以發佈XML嗎?確保類的包是相同的。 – Rajesh 2012-04-27 10:07:18

+0

@kioels:使用FriendSchedule的完整代碼編輯您的文章,包括用XML代碼編輯的pacage名稱和xml – 2012-04-27 10:17:11

+0

,當然還有FriendSchedule包名... thx用於響應btw ... – Kioels 2012-04-27 10:25:08

回答

0

我重新啓動我的日食一次和項目管理運行良好沒有任何錯誤(我不知道爲什麼發生這種情況,我沒有任何好的指定答案)

但無論如何,謝謝你的迴應...