2014-11-01 2 views
0

즐겨 찾기 목록에 책갈피를 추가 할 수있는 활동이 있습니다. 각 즐겨 찾기에 버튼이 있습니다. 해당 버튼을 클릭하면 해당 특정 활동으로 이동해야합니다. 그러나 그것은 나에게 오류를 보여줍니다. 앱이 중단되지는 않지만 북마크 된 활동은 클릭에서 시작되지 않습니다. 여기 다른 패키지에있는 활동을 시작할 수 없습니다 (의도에서)

는 "즐겨 찾기"활동에 대한 코드입니다 :

public class FavouritesActivity extends Activity { 

private TextView mEmptyText; 
private LinearLayout mBookmarkLayout; 

private Context mContext; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.favourites_layout); 

    mContext = this; 

    mEmptyText = (TextView) findViewById(R.id.empty_textview); 
    mBookmarkLayout = (LinearLayout) findViewById(R.id.bookmark_insert_point); 

    getAllKeys(); 

} 

private void getAllKeys() 
{ 
    SharedPreferences sp = this.getSharedPreferences("favs", MODE_PRIVATE); 
    Map<String,?> keys = sp.getAll(); 

    int count = 0; 
    for(Map.Entry<String,?> entry : keys.entrySet()) 
    { 
     String value = entry.getValue().toString(); 
     System.out.println("!!!!!!!!!!!!!!!!!value = "+value); 
     String delimiter = ","; 
     String[] values_array = value.split(delimiter); 
     addBookmark(values_array); 
     count++; //keep track of the number of bookmarks 
    } 

    //if there are no bookmarks, display a text view saying so. Otherwise, make the text view go away 
    if (count == 0) 
    { 
     mEmptyText.setVisibility(View.VISIBLE); 
     mEmptyText.setText(getString(R.string.no_favs)); 
    } 
    else 
     mEmptyText.setVisibility(View.GONE); 

} 

private void addBookmark(String[] values_array) 
{  
    LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View v = vi.inflate(R.layout.fav_individual, null); 

    TextView text = (TextView) v.findViewById(R.id.bookmark_text); 
    text.setSelected(true); 
    ImageButton button = (ImageButton) v.findViewById(R.id.bookmark_button); 
    v.getContext(); 

    text.setText(values_array[1]); 

    final String myClass = values_array[0]; 
    button.setOnClickListener(new View.OnClickListener() 
    { 
     @Override 
     public void onClick(View v) 
     { 
      Class<?> cl = null; 
      try { 
       cl = Class.forName(myClass); 
       Intent myIntent = new Intent(mContext, cl); 
       startActivity(myIntent); 
       } catch (ClassNotFoundException e) { 
       e.printStackTrace(); 
       } 
       } 
    }); 

    // insert into main view 
    mBookmarkLayout.addView(v, 0, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); 
    System.out.println("!!!!!!!!!!!!!!!!!!!!Just added a view"); 
} 

} 

오류가 정확히이 라인에서 온 클릭 방법입니다 :

cl = Class.forName(myClass); 

그것은 나에게 ClassNotFoundException가 있습니다.

이 코드를 사용하면이 패키지 안에있는 활동을 시작할 수 있습니다. 그러나 문제는 내가 시작하려는 활동이 다른 패키지 안에 있다는 것입니다. logcat은 현재 패키지에서 활동을 찾을 수 없다고 말합니다.

그렇다면 필자의 경우 다른 패키지에서 액티비티를 열 수 있습니까? 해당 활동은 매니페스트 파일에 선언되어 있습니다.

감사합니다.

답변

0

FavouritesActivity에서 다른 패키지를 가져 왔습니까? 코드 상단에이 줄을 추가하고 다른 패키지와 일치하도록 단어를 바꿉니다.

+0

고맙지 만 작동하지 않습니다. 그것은 수입이 사용되지 않습니다 말한다 –

+0

여기에 대답은, 제 생각에는 ... http://stackoverflow.com/questions/13326890/class-forname-and-classnotfoundexception?answertab=active#tab-top –

관련 문제