所以我对Android studio还是个新手。我通常只看教程,然后跟着学习,了解每件事是什么,看看每件事是如何工作的。我试着按照一个带有折叠工具栏的卡片视图/回收器视图的教程,在完成代码后(几乎与视频中的人显示的完全相同),应用程序仍然不能运行。我唯一改变的是图标,几个可绘制的和一些值(我在代码中对其进行了编辑)。
下面是我关注的源代码的帖子:https://github.com/delaroy/AndroidCardView?files=1
正如我所说的,没有任何错误或任何东西。但当我运行这个应用程序时,它立即崩溃了。
这也是我的第一篇文章,所以如果需要任何其他信息,请让我知道。
正如我所说的,我只更改了图片和一些变量的名称等等。而且,所有改变的东西都是固定在值之类的。
我已经在我的手机上运行了其他应用程序,没有任何问题。
不确定是电话问题还是什么问题。
我使用的是一台运行安卓5.0的Note3。
发布于 2019-04-20 22:16:55
有时它是由于xml文件中的id重复而发生的,例如,如果你有两个xml文件,比如Main activity和Home,你都有ID为myTextview的Textview,所以一旦在你的类中使用了这个(Id),android studio就不会算作错误,但是一旦你点击了,应用程序就会在这两个活动中崩溃。Enyoy编码
发布于 2016-09-14 15:53:49
您必须检查日志以了解导致崩溃的异常。在日志(IDE的下半部分)中,将有异常的名称、启动它的元素以及指向发现问题的代码行的链接。
如果仍然无法通过这种方式找到错误,可以在调试期间希望应用程序停止的代码行左侧设置断点,然后在调试模式下运行应用程序以查看到底发生了什么。
另一个技巧:通常,当我确信我的代码是正确的,但它运行但崩溃,这是关于声明清单中的所有活动(或所有服务)并设置所有所需的权限。因为在这种情况下,在运行应用程序之前没有明显的错误。让我们知道!
发布于 2016-09-15 16:48:25
好吧,这可能是关于Toolbar的,让我们看看它是如何工作的。
在android中使用widget工具栏比使用actionbar更好,因为...
为此,您必须在Gradle ( v7 :app)中添加(如果没有) appcompact模块库,如下所示:
dependecies { compile 'com.android.support:appcompat-v7:+' }要删除操作栏并插入工具栏,您必须:
1. remove actionbar from manifest setting a no actionbar style:
<application
android:theme="@style/Theme.AppCompact.Light.NoActionBar"
/>
2. insert Toolbar widget into the layout of the activity:
<LinearLayout ...>
...
<android.support.v7.widget.Toolbar
android:id="@+id/mytoolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="8dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</LinearLayout>
3. insert the widget into the activity and set it as support toolbar:
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar myToolbar = (Toolbar) findViewById(R.id.mytoolbar);
myToolbar.setLogo(R.mipmap.ic_launcher);
myToolbar.setTitle("Titolo");
myToolbar.setSubtitle(R.string.sottotitolo);
setSupportActionBar(myToolbar);
}
4. create a menù for the Toolbar, into res>menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/new_game"
android:icon="@drawable/ic_new_game"
android:title="@string/new_game"
android:showAsAction="ifRoom"/>
<item android:id="@+id/help"
android:icon="@drawable/ic_help"
android:title="@string/help"
android:showAsAction="never"/>
<item android:id="@+id/tutorials"
android:icon="@drawable/ic_tuts"
android:title="@string/tutorials"
android:showAsAction="always"/>
</menu>
5. bind menù to toolbar through the two methods into the activity:
@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 item selection
switch (item.getItemId()) {
case R.id.new_game:
newGame();
return true;
case R.id.help:
showHelp();
return true;
default:
return super.onOptionsItemSelected(item);
}
}https://stackoverflow.com/questions/39481804
复制相似问题