当我单击按钮转到其他 activity 时,应用程序在 android 工作室关闭?
Application goes off on android studio when I click button to go to other activity?
我检查了每件事,我确定我的代码在活动方面是正确的,但我无法找出错误 我尝试检查 AndroidManifest.xml 但我没有看到问题.
退出模拟器时出现此错误:
*
> V/FA: onActivityCreated D/AndroidRuntime: Shutting down VM
> E/AndroidRuntime: FATAL EXCEPTION: main
> Process: com.example.dictionnary, PID: 7465
> java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dictionnary/com.example.dictionnary.PlannerActivity}:
> android.view.InflateException: Binary XML file line #72 in
> com.example.dictionnary:layout/activity_planner: Binary XML file line
> #72 in com.example.dictionnary:layout/activity_planner: Error inflating class android.support.widget.RecyclerView
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
> at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
> at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
> at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
> at android.os.Handler.dispatchMessage(Handler.java:107)
> at android.os.Looper.loop(Looper.java:214)
> at android.app.ActivityThread.main(ActivityThread.java:7356)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
> Caused by: android.view.InflateException: Binary XML file line #72 in com.example.dictionnary:layout/activity_planner: Binary XML file line #72 in com.example.dictionnary:layout/activity_planner:
> Error inflating class android.support.widget.RecyclerView
> Caused by: android.view.InflateException: Binary XML file line #72 in com.example.dictionnary:layout/activity_planner: Error inflating class android.support.widget.RecyclerView
> Caused by: java.lang.ClassNotFoundException: android.support.widget.RecyclerView
> at java.lang.Class.classForName(Native Method)
> at java.lang.Class.forName(Class.java:454)
> at android.view.LayoutInflater.createView(LayoutInflater.java:815)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
> at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
> at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
> at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
> at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
> at com.example.dictionnary.PlannerActivity.onCreate(PlannerActivity.java:36)
> at android.app.Activity.performCreate(Activity.java:7802)
> at android.app.Activity.performCreate(Activity.java:7791)
> at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
> at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
> at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
> at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
> at android.os.Handler.dispatchMessage(Handler.java:107)
> at android.os.Looper.loop(Looper.java:214)
> at android.app.ActivityThread.main(ActivityThread.java:7356)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
> E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't
> find class "android.support.widget.RecyclerView" on path:
> DexPathList[[zip file
> "/data/app/com.example.dictionnary-NMLUdW6Y7szWNvSxehbDwQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dictionnary-NMLUdW6Y7szWNvSxehbDwQ==/lib/x86,
> /system/lib, /system/product/lib]]
> at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
> ... 28 more
*
这是我的简单 MainActivity
public class MainActivity extends AppCompatActivity {
private Button searchButton, plannerButton;
@Override
public void onCreate(@Nullable Bundle savedInstanceState ) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
searchButton = (Button) findViewById (R.id.main_search);
plannerButton = (Button) findViewById (R.id.main_planner);
searchButton.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick(View v) {
openActivity2();
}
});
}
public void openActivity2(){
Intent intent = new Intent (this, PlannerActivity.class);
startActivity(intent);
}
}
And here my activity_main.xml:
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/welcome"
tools:context=".MainActivity">
<ImageView
android:id="@+id/app_logo"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:src="@drawable/applogo"
/>
<TextView
android:id="@+id/app_slogan"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="88dp"
android:layout_marginTop="140dp"
android:text="Discover Apiales"
android:textAlignment="center"
android:textColor="@color/colorPrimary"
android:textSize="22dp"
android:textStyle="bold|italic"
/>
<Button
android:id="@+id/main_planner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/buttons"
android:padding="20dp"
android:textAllCaps="false"
android:textSize="10sp"
android:text="Planner"
android:textColor="@android:color/white"
/>
<Button
android:id="@+id/main_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/main_planner"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/input_design"
android:padding="20dp"
android:textAllCaps="false"
android:textSize="10sp"
android:text="Recherche "
android:textColor="@android:color/white"
/>
</RelativeLayout>
and here is the second Activity I want to go to once I click on search button, then I'll do the same with planner button to go to an other activity
public class PlannerActivity extends AppCompatActivity {
TextView titlepage, subtitlepage, endpage;
Button btnAddNew;
DatabaseReference reference;
RecyclerView ourdoes;
ArrayList<MyDoes> list;
DoesAdapter doesAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_planner);
titlepage = findViewById(R.id.titlepage);
subtitlepage = findViewById(R.id.subtitlepage);
endpage = findViewById(R.id.endpage);
btnAddNew = findViewById(R.id.btnAddNew);
// import font
Typeface MLight = Typeface.createFromAsset(getAssets(), "fonts/ML.ttf");
Typeface MMedium = Typeface.createFromAsset(getAssets(), "fonts/MM.ttf");
// customize font
titlepage.setTypeface(MMedium);
subtitlepage.setTypeface(MLight);
endpage.setTypeface(MLight);
btnAddNew.setTypeface(MLight);
btnAddNew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent a = new Intent(PlannerActivity.this,NewTaskAct.class);
startActivity(a);
}
});
// working with data
ourdoes = findViewById(R.id.ourdoes);
ourdoes.setLayoutManager(new LinearLayoutManager (this));
list = new ArrayList<MyDoes>();
// get data from firebase
reference = FirebaseDatabase.getInstance().getReference().child("DoesApp");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// set code to retrive data and replace layout
for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
{
MyDoes p = dataSnapshot1.getValue(MyDoes.class);
list.add(p);
}
doesAdapter = new DoesAdapter(PlannerActivity.this, list);
ourdoes.setAdapter(doesAdapter);
doesAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
// set code to show an error
Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_SHORT).show();
}
});
}
}
Here is my activity_planner.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F4F4"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/colorPrimaryDark"
android:layout_height="198dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_marginLeft="16dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/titlepage"
android:layout_marginTop="20dp"
android:textSize="32sp"
android:textColor="#FFF"
android:text="My Does"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/subtitlepage"
android:textSize="18sp"
android:textColor="#4A4E6A"
android:layout_marginTop="8dp"
android:text="Finish Them Quickly Today"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:layout_marginTop="35dp"
android:layout_marginLeft="60dp"
android:id="@+id/btnAddNew"
android:text="+"
android:background="@drawable/bgbtnnew"
android:textSize="38sp"
android:textColor="#FFF"
android:textAlignment="center"
android:layout_width="52dp"
android:layout_height="52dp" />
</LinearLayout>
<View
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:background="#131E69"
android:layout_height="1dp" />
</LinearLayout>
<android.support.widget.RecyclerView
android:id="@+id/ourdoes"
android:layout_width="match_parent"
android:layout_marginTop="-60dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/endpage"
android:textSize="16sp"
android:textColor="#9A9A9A"
android:layout_marginTop="20dp"
android:text="No More Does"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
error when the app crashes and quit to go back to the menu of the emulator
V/FA: 连接到远程服务
V/FA: Activity 已暂停,时间:1117469
D/AndroidRuntime: 关闭虚拟机
E/AndroidRuntime:致命异常:main
进程:com.example.dictionnary,PID:11242
java.lang.RuntimeException: 无法启动 activity ComponentInfo{com.example.dictionnary/com.example.dictionnary.PlannerActivity}: java.lang.RuntimeException: 未找到字体资源 fonts/ML .ttf文件
在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
在 android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
在 android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
在 android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
在 android.os.Handler.dispatchMessage(Handler.java:107)
在 android.os.Looper.loop(Looper.java:214)
在 android.app.ActivityThread.main(ActivityThread.java:7356)
在 java.lang.reflect.Method.invoke(本机方法)
在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
原因:java.lang.RuntimeException:未找到字体资源 fonts/ML.ttf
在 android.graphics.Typeface.createFromAsset(Typeface.java:965)
在 com.example.dictionnary.PlannerActivity.onCreate(PlannerActivity.java:45)
在 android.app.Activity.performCreate(Activity.java:7802)
在 android.app.Activity.performCreate(Activity.java:7791)
在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
在 android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
在 android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
在 android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
在 android.os.Handler.dispatchMessage(Handler.java:107)
在 android.os.Looper.loop(Looper.java:214)
在 android.app.ActivityThread.main(ActivityThread.java:7356)
在 java.lang.reflect.Method.invoke(本机方法)
在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process:发送信号。 PID:11242 SIG:9
你能检查一下你的 activity_planner.xml 文件吗?检查行号 72
android.support.widget.RecyclerView.
您使用的是 Recyclerview 的旧依赖项,可能尚未完全迁移到 AndroidX
只需替换
android.support.widget.RecyclerView
在你的 xml
androidx.recyclerview.widget.RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F4F4"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/colorPrimaryDark"
android:layout_height="198dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_marginLeft="16dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/titlepage"
android:layout_marginTop="20dp"
android:textSize="32sp"
android:textColor="#FFF"
android:text="My Does"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/subtitlepage"
android:textSize="18sp"
android:textColor="#4A4E6A"
android:layout_marginTop="8dp"
android:text="Finish Them Quickly Today"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:layout_marginTop="35dp"
android:layout_marginLeft="60dp"
android:id="@+id/btnAddNew"
android:text="+"
android:background="@drawable/bgbtnnew"
android:textSize="38sp"
android:textColor="#FFF"
android:textAlignment="center"
android:layout_width="52dp"
android:layout_height="52dp" />
</LinearLayout>
<View
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:background="#131E69"
android:layout_height="1dp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/ourdoes"
android:layout_width="match_parent"
android:layout_marginTop="-60dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/endpage"
android:textSize="16sp"
android:textColor="#9A9A9A"
android:layout_marginTop="20dp"
android:text="No More Does"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
我检查了每件事,我确定我的代码在活动方面是正确的,但我无法找出错误 我尝试检查 AndroidManifest.xml 但我没有看到问题. 退出模拟器时出现此错误:
*
> V/FA: onActivityCreated D/AndroidRuntime: Shutting down VM
> E/AndroidRuntime: FATAL EXCEPTION: main
> Process: com.example.dictionnary, PID: 7465
> java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dictionnary/com.example.dictionnary.PlannerActivity}:
> android.view.InflateException: Binary XML file line #72 in
> com.example.dictionnary:layout/activity_planner: Binary XML file line
> #72 in com.example.dictionnary:layout/activity_planner: Error inflating class android.support.widget.RecyclerView
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
> at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
> at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
> at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
> at android.os.Handler.dispatchMessage(Handler.java:107)
> at android.os.Looper.loop(Looper.java:214)
> at android.app.ActivityThread.main(ActivityThread.java:7356)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
> Caused by: android.view.InflateException: Binary XML file line #72 in com.example.dictionnary:layout/activity_planner: Binary XML file line #72 in com.example.dictionnary:layout/activity_planner:
> Error inflating class android.support.widget.RecyclerView
> Caused by: android.view.InflateException: Binary XML file line #72 in com.example.dictionnary:layout/activity_planner: Error inflating class android.support.widget.RecyclerView
> Caused by: java.lang.ClassNotFoundException: android.support.widget.RecyclerView
> at java.lang.Class.classForName(Native Method)
> at java.lang.Class.forName(Class.java:454)
> at android.view.LayoutInflater.createView(LayoutInflater.java:815)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
> at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
> at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
> at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
> at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
> at com.example.dictionnary.PlannerActivity.onCreate(PlannerActivity.java:36)
> at android.app.Activity.performCreate(Activity.java:7802)
> at android.app.Activity.performCreate(Activity.java:7791)
> at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
> at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
> at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
> at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
> at android.os.Handler.dispatchMessage(Handler.java:107)
> at android.os.Looper.loop(Looper.java:214)
> at android.app.ActivityThread.main(ActivityThread.java:7356)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
> E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't
> find class "android.support.widget.RecyclerView" on path:
> DexPathList[[zip file
> "/data/app/com.example.dictionnary-NMLUdW6Y7szWNvSxehbDwQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dictionnary-NMLUdW6Y7szWNvSxehbDwQ==/lib/x86,
> /system/lib, /system/product/lib]]
> at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
> ... 28 more
*
这是我的简单 MainActivity
public class MainActivity extends AppCompatActivity {
private Button searchButton, plannerButton;
@Override
public void onCreate(@Nullable Bundle savedInstanceState ) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
searchButton = (Button) findViewById (R.id.main_search);
plannerButton = (Button) findViewById (R.id.main_planner);
searchButton.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick(View v) {
openActivity2();
}
});
}
public void openActivity2(){
Intent intent = new Intent (this, PlannerActivity.class);
startActivity(intent);
}
}
And here my activity_main.xml:
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/welcome"
tools:context=".MainActivity">
<ImageView
android:id="@+id/app_logo"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:src="@drawable/applogo"
/>
<TextView
android:id="@+id/app_slogan"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="88dp"
android:layout_marginTop="140dp"
android:text="Discover Apiales"
android:textAlignment="center"
android:textColor="@color/colorPrimary"
android:textSize="22dp"
android:textStyle="bold|italic"
/>
<Button
android:id="@+id/main_planner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/buttons"
android:padding="20dp"
android:textAllCaps="false"
android:textSize="10sp"
android:text="Planner"
android:textColor="@android:color/white"
/>
<Button
android:id="@+id/main_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/main_planner"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/input_design"
android:padding="20dp"
android:textAllCaps="false"
android:textSize="10sp"
android:text="Recherche "
android:textColor="@android:color/white"
/>
</RelativeLayout>
and here is the second Activity I want to go to once I click on search button, then I'll do the same with planner button to go to an other activity
public class PlannerActivity extends AppCompatActivity {
TextView titlepage, subtitlepage, endpage;
Button btnAddNew;
DatabaseReference reference;
RecyclerView ourdoes;
ArrayList<MyDoes> list;
DoesAdapter doesAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_planner);
titlepage = findViewById(R.id.titlepage);
subtitlepage = findViewById(R.id.subtitlepage);
endpage = findViewById(R.id.endpage);
btnAddNew = findViewById(R.id.btnAddNew);
// import font
Typeface MLight = Typeface.createFromAsset(getAssets(), "fonts/ML.ttf");
Typeface MMedium = Typeface.createFromAsset(getAssets(), "fonts/MM.ttf");
// customize font
titlepage.setTypeface(MMedium);
subtitlepage.setTypeface(MLight);
endpage.setTypeface(MLight);
btnAddNew.setTypeface(MLight);
btnAddNew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent a = new Intent(PlannerActivity.this,NewTaskAct.class);
startActivity(a);
}
});
// working with data
ourdoes = findViewById(R.id.ourdoes);
ourdoes.setLayoutManager(new LinearLayoutManager (this));
list = new ArrayList<MyDoes>();
// get data from firebase
reference = FirebaseDatabase.getInstance().getReference().child("DoesApp");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// set code to retrive data and replace layout
for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
{
MyDoes p = dataSnapshot1.getValue(MyDoes.class);
list.add(p);
}
doesAdapter = new DoesAdapter(PlannerActivity.this, list);
ourdoes.setAdapter(doesAdapter);
doesAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
// set code to show an error
Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_SHORT).show();
}
});
}
}
Here is my activity_planner.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F4F4"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/colorPrimaryDark"
android:layout_height="198dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_marginLeft="16dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/titlepage"
android:layout_marginTop="20dp"
android:textSize="32sp"
android:textColor="#FFF"
android:text="My Does"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/subtitlepage"
android:textSize="18sp"
android:textColor="#4A4E6A"
android:layout_marginTop="8dp"
android:text="Finish Them Quickly Today"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:layout_marginTop="35dp"
android:layout_marginLeft="60dp"
android:id="@+id/btnAddNew"
android:text="+"
android:background="@drawable/bgbtnnew"
android:textSize="38sp"
android:textColor="#FFF"
android:textAlignment="center"
android:layout_width="52dp"
android:layout_height="52dp" />
</LinearLayout>
<View
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:background="#131E69"
android:layout_height="1dp" />
</LinearLayout>
<android.support.widget.RecyclerView
android:id="@+id/ourdoes"
android:layout_width="match_parent"
android:layout_marginTop="-60dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/endpage"
android:textSize="16sp"
android:textColor="#9A9A9A"
android:layout_marginTop="20dp"
android:text="No More Does"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
error when the app crashes and quit to go back to the menu of the emulator
V/FA: 连接到远程服务 V/FA: Activity 已暂停,时间:1117469 D/AndroidRuntime: 关闭虚拟机 E/AndroidRuntime:致命异常:main 进程:com.example.dictionnary,PID:11242 java.lang.RuntimeException: 无法启动 activity ComponentInfo{com.example.dictionnary/com.example.dictionnary.PlannerActivity}: java.lang.RuntimeException: 未找到字体资源 fonts/ML .ttf文件 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 在 android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 在 android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 在 android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 在 android.os.Handler.dispatchMessage(Handler.java:107) 在 android.os.Looper.loop(Looper.java:214) 在 android.app.ActivityThread.main(ActivityThread.java:7356) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 原因:java.lang.RuntimeException:未找到字体资源 fonts/ML.ttf 在 android.graphics.Typeface.createFromAsset(Typeface.java:965) 在 com.example.dictionnary.PlannerActivity.onCreate(PlannerActivity.java:45) 在 android.app.Activity.performCreate(Activity.java:7802) 在 android.app.Activity.performCreate(Activity.java:7791) 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 在 android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 在 android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 在 android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 在 android.os.Handler.dispatchMessage(Handler.java:107) 在 android.os.Looper.loop(Looper.java:214) 在 android.app.ActivityThread.main(ActivityThread.java:7356) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) I/Process:发送信号。 PID:11242 SIG:9
你能检查一下你的 activity_planner.xml 文件吗?检查行号 72
android.support.widget.RecyclerView.
您使用的是 Recyclerview 的旧依赖项,可能尚未完全迁移到 AndroidX 只需替换
android.support.widget.RecyclerView
在你的 xml
androidx.recyclerview.widget.RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F4F4"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/colorPrimaryDark"
android:layout_height="198dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_marginLeft="16dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/titlepage"
android:layout_marginTop="20dp"
android:textSize="32sp"
android:textColor="#FFF"
android:text="My Does"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/subtitlepage"
android:textSize="18sp"
android:textColor="#4A4E6A"
android:layout_marginTop="8dp"
android:text="Finish Them Quickly Today"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:layout_marginTop="35dp"
android:layout_marginLeft="60dp"
android:id="@+id/btnAddNew"
android:text="+"
android:background="@drawable/bgbtnnew"
android:textSize="38sp"
android:textColor="#FFF"
android:textAlignment="center"
android:layout_width="52dp"
android:layout_height="52dp" />
</LinearLayout>
<View
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:background="#131E69"
android:layout_height="1dp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/ourdoes"
android:layout_width="match_parent"
android:layout_marginTop="-60dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/endpage"
android:textSize="16sp"
android:textColor="#9A9A9A"
android:layout_marginTop="20dp"
android:text="No More Does"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>