2011-02-04 2 views
0

Я получаю сообщение об ошибке, когда я нажимаю ссылку в своей первой активности (проводник), я бы хотел, чтобы она создала файл, который я создал (AndroidExplorer). Что-то не так с кодом кода моего кода или с моим манифестом.Переключение с одной операции на другую проблему с файлом манифеста?

Любая помощь будет оценена

Проводник Класс

public class Explorer extends Activity{ 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Button picture = (Button)findViewById(R.id.picture); 

    picture.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View view) { 
      Intent intent = new Intent(Explorer.this, AndroidExplorer.class); 
      startActivity(intent); 
      finish(); 
     } 

     }); 
    } 
} 

AndroidExplorer класс

public class AndroidExplorer extends ListActivity { 

private List<String> item = null; 
private List<String> path = null; 
private String root="/sdcard/DCIM/camera/"; 
private TextView myPath; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main2); 
    myPath = (TextView)findViewById(R.id.path); 
    getDir(root); 
} 

private void getDir(String dirPath) 
{ 
    myPath.setText("Location: " + dirPath); 

    item = new ArrayList<String>(); 
    path = new ArrayList<String>(); 

    File f = new File(dirPath); 
    File[] files = f.listFiles(); 

    if(!dirPath.equals(root)) 
    { 

     item.add(root); 
     path.add(root); 

     item.add("../"); 
     path.add(f.getParent()); 

    } 

    for(int i=0; i < files.length; i++) 
    { 
      File file = files[i]; 
      path.add(file.getPath()); 
      if(file.isDirectory()) 
       item.add(file.getName() + "/"); 
      else 
       item.add(file.getName()); 
    } 

    ArrayAdapter<String> fileList = 
     new ArrayAdapter<String>(this, R.layout.row, item); 
    setListAdapter(fileList); 
} 

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 

    File file = new File(path.get(position)); 

    if (file.isDirectory()) 
    { 
     if(file.canRead()) 
      getDir(path.get(position)); 
     else 
     { 
      new AlertDialog.Builder(this) 
      .setIcon(R.drawable.icon) 
      .setTitle("[" + file.getName() + "] folder can't be read!") 
      .setPositiveButton("OK", 
        new DialogInterface.OnClickListener() { 

         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          // TODO Auto-generated method stub 
         } 
        }).show(); 
     } 
    } 
    else 
    { 
     new AlertDialog.Builder(this) 
      .setIcon(R.drawable.icon) 
      .setTitle("[" + file.getName() + "]") 
      .setPositiveButton("OK", 
        new DialogInterface.OnClickListener() { 

         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          // TODO Auto-generated method stub 
         } 
        }).show(); 
    } 
}} 

файл манифеста

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.Explorer" 
    android:versionCode="1" 
    android:versionName="1.0"> 
<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name=".Explorer" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
<activity android:name=".AndroidExplorer" 
     android:label="Screen 2 - New actvity."> 

    </activity> 
</application> 


</manifest> 
+1

Пожалуйста, можете ли вы предоставить выходные данные ошибки logcat? –

+0

Тип элемента «активность» должен быть завершен соответствующим концевым тегом «». и Имя атрибута «активность», связанное с типом элемента «приложение», должно сопровождаться символом «=». – James

+0

Я задерживаю ... Ответ: убедитесь, что в вашем эмуляторе телефона есть SD-карта ... – James

ответ

1

Ну, видя, как корневой вар iable - это путь к sdcard, кажется, что каталог не будет существовать, если у вас нет подключенной SD-карты. Думаю, вам, вероятно, следует отловить эту ошибку и бросить всплывающее окно или что-то, что позволит пользователю знаете, нужна SD-карта.

Смежные вопросы