我在Android Studio版本1.2.1.1 API 22中创建了材料设计。生成成功,零错误和零警告。当我运行应用程序时,它给出运行时错误“不幸的是,'应用程序名称'已停止工作”。
Mystyles.xml
<resources>
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">@color/textColorPrimary</item>
<item name="android:windowBackground">@color/windowBackground</item>
</style>
</resources>
更新了< code>styles.xml -
<resources>
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">@color/textColorPrimary</item>
<item name="android:windowBackground">@color/windowBackground</item>
</style>
</resources>
这是我的日志:
05-28 13:59:03.787 8338-8338/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
05-28 13:59:03.945 8338-8338/com.techsnapr.materialdesign D/AndroidRuntime﹕ Shutting down VM
05-28 13:59:03.947 8338-8338/com.techsnapr.materialdesign E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.techsnapr.materialdesign, PID: 8338
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.techsnapr.materialdesign/com.techsnapr.materialdesign.activity.MainActivity}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:360)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.techsnapr.materialdesign.activity.MainActivity.onCreate(MainActivity.java:28)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Logcat高亮(MainActivity.java:28)-setContentView(R.layout.activity_main);
这是主要活动.java
package com.techsnapr.materialdesign.activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.techsnapr.materialdesign.R;
public class MainActivity extends ActionBarActivity implements FragmentDrawer.FragmentDrawerListener {
private static String TAG = MainActivity.class.getSimpleName();
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
// display the first navigation drawer view on app launch
displayView(0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
if(id == R.id.action_search){
Toast.makeText(getApplicationContext(), "Search action is selected!", Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onDrawerItemSelected(View view, int position) {
displayView(position);
}
private void displayView(int position) {
Fragment fragment = null;
String title = getString(R.string.app_name);
switch (position) {
case 0:
fragment = new HomeFragment();
title = getString(R.string.title_home);
break;
case 1:
fragment = new FriendsFragment();
title = getString(R.string.title_friends);
break;
case 2:
fragment = new MessagesFragment();
title = getString(R.string.title_messages);
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_body, fragment);
fragmentTransaction.commit();
// set the toolbar title
getSupportActionBar().setTitle(title);
}
}
}
这是来自Gradle Build的消息:
Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72211Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72103Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42211Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug UP-TO-DATE
:app:zipalignDebug UP-TO-DATE
:app:assembleDebug UP-TO-DATE
Information:BUILD SUCCESSFUL
Information:Total time: 3.904 secs
Information:0 errors
Information:0 warnings
Information:See complete output in console
我已经尝试了所有可能的解决方案。仍然无法运行该应用程序,请帮忙。
尝试从以下位置更改app/src/main/RES/values/styles . XML:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
收件人:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
尝试删除 中的Android前缀
也替换<代码>
还有一件事,支持库的修订版22.1.0中不建议使用ActionBaractive,因此应使用AppCompatActive而不是ActionBaractive。这与问题无关,只是一个建议。
希望这将帮助您解决问题,因为您的代码的所有其他部分看起来都没问题。
这个想法是在警报开始时启动一个游戏。我在下面展示了manifest.xml。如果我犯了错误,请纠正我。因为我刚接触Android系统,所以我无法理解它。PS:我已经搜索了其他类似的问题,并纠正了许多其他错误,但问题仍然存在。 这是我从教程(AndroidTimeActivity)中获得的警报代码: 这是AlarmReceiver类:
这个想法是在警报开始时启动一个游戏。我已经在下面展示了manifest.xml。如果我犯了错误,请纠正我。因为我是Android的新手,所以我不太懂。PS:我已经搜索了其他类似的问题,并更正了很多其他错误,但问题依然存在。 这是我从一个教程(AndroidTimeActivity)得到的警报代码: 这是AlarmReceiver类: 这里是Manager类,当警报接收器接收到意图时,我要调用它:
代码 和logcat 06-03 16:59:26.570 972 0-9757/com.example.abhijitroy.superhero E/AndroidRuntime:致命异常:AsyncTask#1进程:com.example.abhijitroy.superhero,PID:9720 java.lang.RuntimeException:在Android.os.AsyncTask
我对Android编程完全陌生。我正在制作的第一个应用程序遇到了一些问题。每次我运行应用程序时,我的手机(我正在使用它来测试和调试我的应用程序)上会弹出一条消息说“不幸的是,MyNewApp3已停止”。这个错误甚至无法打开我的应用程序。我如何解决这个问题? 这是我的代码: 我的LogCat输出(这是我在看到别人建议别人放置LogCat输出后发布的;我不知道它是用来做什么的): 01-12 11:4
我在Android Studio 6.0上的模拟器出现了上述崩溃,但在我的设备6.0.1上没有崩溃。模拟器有时会启动相机,但它大多会崩溃,在logcat中没有任何东西来给我指明正确的方向。有人知道这里可能发生了什么吗? 此外,这里有一个图像,当它确实通过。image_capture_camera logcat:
我想在通知上打开我的MapsActive单击通知正常工作,但当我单击通知时,它会让我停止应用程序 通知活动。班 地图civity.class activity_map LogCat ethod.invokeActivityTcom.android.internal.os.LaunchActive(ActivityTaller.run)atnit.java:726ActivityTcom.andro