2017-02-20 6 views
0

Я работаю над очень простым установщиком обоев. Приложение отлично работает на эмуляторе, но не работает на устройстве. Я также пробовал приложение на других устройствах, и результат такой же.Исключение времени выполнения Android. Не удалось запустить активность

MainActivity.java:

public class MainActivity extends AppCompatActivity { 
    ImageView iv; 
    FloatingActionButton fab,fab2; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     toolbar.setTitleTextColor(getResources().getColor(R.color.white)); 
     setSupportActionBar(toolbar); 
     fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setImageResource(R.drawable.plus_24x24); 
     fab.setBackgroundColor(getResources().getColor(R.color.colorAccent)); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Intent intent = new Intent(); 
       intent.setType("image/*"); 
       intent.setAction(Intent.ACTION_GET_CONTENT); 
       startActivityForResult(Intent.createChooser(intent, "Select  Picture"), 9999); 

      } 
     }); 
     fab2=(FloatingActionButton)findViewById(R.id.fab2); 
     fab2.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); 
     fab2.setImageResource(R.drawable.ic_done_white); 
     fab2.setVisibility(View.INVISIBLE); 
     fab2.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       WallpaperManager myWallpaperManager 
        = WallpaperManager.getInstance(getApplicationContext()); 
       try { 
        myWallpaperManager.setBitmap(((BitmapDrawable)iv.getDrawable()).getBitmap()); 
        Snackbar.make(findViewById(android.R.id.content), "Wallpaper set", Snackbar.LENGTH_SHORT).show(); 
       } catch (IOException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 
     }); 
     iv=(ImageView)findViewById(R.id.imageView); 
    } 

    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

     if (requestCode == 9999 && resultCode == RESULT_OK && data != null) { 
      fab2.setVisibility(View.VISIBLE); 
      Uri imageUri = data.getData(); 
      iv.setImageURI(imageUri); 

     } 
     else { 
      Snackbar.make(findViewById(android.R.id.content), "No image selected", Snackbar.LENGTH_SHORT).show(); 
     } 
    } 
} 

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:layout_height="match_parent" 
android:layout_width="match_parent" 
xmlns:android.support.design="http://schemas.android.com/tools" 
android:orientation="horizontal" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 


<android.support.v7.widget.CardView 
    android:id="@+id/card_view" 
    android:layout_gravity="center" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/toolbar" 
    android:layout_marginTop="@dimen/ef_margin_medium" 
    android:layout_marginLeft="@dimen/ef_margin_medium" 
    android:layout_marginRight="@dimen/ef_margin_medium" 
    android:layout_marginBottom="@dimen/ef_margin_medium" 
    ads:cardCornerRadius="6dp" 
    ads:cardElevation="6dp" 
    > 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_marginEnd="@dimen/ef_margin_medium" 
     android:layout_marginRight="@dimen/ef_margin_medium" 
     android:layout_marginBottom="@dimen/ef_margin_medium" 
     /> 

    <ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/imageView" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentBottom="true" /> 


</android.support.v7.widget.CardView> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab2" 
    android:layout_width="wrap_content" 
    android:layout_height="51dp" 
    app:fabSize="mini" 
    android:backgroundTint="@color/colorAccent" 
    android:layout_marginTop="34dp" 
    android:layout_marginRight="11dp" 
    android:layout_marginEnd="11dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignRight="@+id/card_view" 
    android:layout_alignEnd="@+id/card_view" /> 
</RelativeLayout> 

Журнал ошибок:

E/AndroidRuntime: FATAL EXCEPTION: main 
       Process: com.entripleaardee.incognitogallery, PID: 4571 
       java.lang.RuntimeException: Unable to start activity ComponentInfo{com.entripleaardee.incognitogallery/com.entripleaardee.incognitogallery.MainActivity}: android.view.InflateException: Binary XML file line #55: Binary XML file line #55: Error inflating class <unknown> 
+1

Пожалуйста, предоставьте несколько следующих строк из вашего сообщения журнала. – MaxV

+0

Наверное, покажите свой файл манифеста. Имеет ли это ''? –

+0

У вас есть ошибка в строке # 55, которая находится на . Кажется, у вас нет библиотеки поддержки. Я считаю, что FAB находится в com.android.support:design. Вы можете просто добавить «compile» com.android.support:design:25.0.1 '' в свои зависимости от градиров –

ответ

1

Вы не можете иметь дополнительные пространства имен в одном файле:

xmlns:ads 

и

xmlns:app 

Удалить xmlns:ads="http://schemas.android.com/apk/res-auto" из RelativeLayout тега и заменить каждое вхождение ads с app.

+0

Спасибо большое, сэр, это сработало. –

+0

Это сайт, на котором вы можете получить ответы на свои программные вопросы. Однако, чтобы знать, является ли ответ ценным для других, он должен быть отмечен как разрешенный и, возможно, данный пункт. Вы можете внести вклад в развитие этого сайта, отметив знак рядом с моим ответом и давая ему преимущество. –

0

Просто замените xmlns:ads на xmlns:app. Нравится (-а) -

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:android.support.design="http://schemas.android.com/tools" 
android:layout_height="match_parent" 
android:layout_width="match_parent" 
android:orientation="horizontal">