gpt4 book ai didi

java - 单击 TextView 时应用程序崩溃

转载 作者:行者123 更新时间:2023-12-01 23:16:27 24 4
gpt4 key购买 nike

xml文件

<TextView
android:id="@+id/manage_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/redirect_call"
android:layout_below="@+id/call_forwarding_togglebutton"
android:layout_marginTop="15dp"
android:text="@string/manage_numbers_label"
android:textSize="17sp"
android:onClick="manage_numbers_onClick"
android:clickable="true" />

mainactivity.java

package com.example.awkwardpanda_redirectcall;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
//import android.view.ViewGroup;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

public void manage_numbers_onClick(View view) {
Intent myIntent = new Intent(this, Manage_numbers.class);
startActivity(myIntent);

}

}

单击后,应导航至此页面。

<TextView
android:id="@+id/set_forward_numbers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/set_forward_numbers_image"
android:layout_marginLeft="10dp"
android:layout_marginTop="-30dp"
android:layout_toRightOf="@+id/set_number_to_receive_image"
android:text="@string/set_forward_numbers_label"
android:textSize="17sp" />

这是下一页的java类:

package com.example.awkwardpanda_redirectcall;

import android.os.Bundle;
import android.app.Activity;
//import android.content.Intent;
import android.view.Menu;
//import android.view.View;
//import android.view.ViewGroup;

public class Manage_numbers extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

/*public void set_forward_numbers_onClick (View view) {
Intent myIntent = new Intent(view.getContext(), Manage_numbers.class);
startActivityForResult(myIntent, 0);
}

public void set_number_to_receive_onClick (View view) {
Intent myIntent = new Intent(view.getContext(), Manage_numbers.class);
startActivityForResult(myIntent, 0);
} */
}

但是,每当我单击模拟器中的 TextView 时,应用程序就会崩溃,我已经研究了这个问题,但似乎找不到解决方案。谢谢

这些是日志。

01-14 04:40:33.378: I/Choreographer(793): Skipped 41 frames!  The application may be doing too much work on its main thread.
01-14 04:40:33.748: D/gralloc_goldfish(793): Emulator without GPU emulation detected.
01-14 04:40:39.398: D/AndroidRuntime(793): Shutting down VM
01-14 04:40:39.428: W/dalvikvm(793): threadid=1: thread exiting with uncaught exception (group=0x41465700)
01-14 04:40:39.458: E/AndroidRuntime(793): FATAL EXCEPTION: main
01-14 04:40:39.458: E/AndroidRuntime(793): java.lang.IllegalStateException: Could not execute method of the activity
01-14 04:40:39.458: E/AndroidRuntime(793): at android.view.View$1.onClick(View.java:3633)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.view.View.performClick(View.java:4240)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.view.View$PerformClick.run(View.java:17721)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.os.Handler.handleCallback(Handler.java:730)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.os.Handler.dispatchMessage(Handler.java:92)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.os.Looper.loop(Looper.java:137)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-14 04:40:39.458: E/AndroidRuntime(793): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 04:40:39.458: E/AndroidRuntime(793): at java.lang.reflect.Method.invoke(Method.java:525)
01-14 04:40:39.458: E/AndroidRuntime(793): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-14 04:40:39.458: E/AndroidRuntime(793): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-14 04:40:39.458: E/AndroidRuntime(793): at dalvik.system.NativeStart.main(Native Method)
01-14 04:40:39.458: E/AndroidRuntime(793): Caused by: java.lang.reflect.InvocationTargetException
01-14 04:40:39.458: E/AndroidRuntime(793): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 04:40:39.458: E/AndroidRuntime(793): at java.lang.reflect.Method.invoke(Method.java:525)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.view.View$1.onClick(View.java:3628)
01-14 04:40:39.458: E/AndroidRuntime(793): ... 11 more
01-14 04:40:39.458: E/AndroidRuntime(793): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.awkwardpanda_redirectcall/com.example.awkwardpanda_redirectcall.Manage_numbers}; have you declared this activity in your AndroidManifest.xml?
01-14 04:40:39.458: E/AndroidRuntime(793): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.app.Activity.startActivityForResult(Activity.java:3390)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.app.Activity.startActivityForResult(Activity.java:3351)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.app.Activity.startActivity(Activity.java:3587)
01-14 04:40:39.458: E/AndroidRuntime(793): at android.app.Activity.startActivity(Activity.java:3555)
01-14 04:40:39.458: E/AndroidRuntime(793): at com.example.awkwardpanda_redirectcall.MainActivity.manage_numbers_onClick(MainActivity.java:27)
01-14 04:40:39.458: E/AndroidRuntime(793): ... 14 more

在 androidmanifest 中声明 Manage_numbers.class 之后(尽管我不确定我是否做得正确)。我收到了这几条日志。

01-15 03:26:13.488: D/gralloc_goldfish(1610): Emulator without GPU emulation detected.
01-15 03:26:16.638: I/Choreographer(1610): Skipped 117 frames! The application may be doing too much work on its main thread.
01-15 03:26:18.528: D/AndroidRuntime(1610): Shutting down VM
01-15 03:26:18.528: W/dalvikvm(1610): threadid=1: thread exiting with uncaught exception (group=0x41465700)
01-15 03:26:18.548: E/AndroidRuntime(1610): FATAL EXCEPTION: main
01-15 03:26:18.548: E/AndroidRuntime(1610): java.lang.IllegalStateException: Could not find a method manage_numbers_onClick(View) in the activity class com.example.awkwardpanda_redirectcall.Manage_numbers for onClick handler on view class android.widget.TextView with id 'manage_number'
01-15 03:26:18.548: E/AndroidRuntime(1610): at android.view.View$1.onClick(View.java:3620)
01-15 03:26:18.548: E/AndroidRuntime(1610): at android.view.View.performClick(View.java:4240)
01-15 03:26:18.548: E/AndroidRuntime(1610): at android.view.View$PerformClick.run(View.java:17721)
01-15 03:26:18.548: E/AndroidRuntime(1610): at android.os.Handler.handleCallback(Handler.java:730)
01-15 03:26:18.548: E/AndroidRuntime(1610): at android.os.Handler.dispatchMessage(Handler.java:92)
01-15 03:26:18.548: E/AndroidRuntime(1610): at android.os.Looper.loop(Looper.java:137)
01-15 03:26:18.548: E/AndroidRuntime(1610): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-15 03:26:18.548: E/AndroidRuntime(1610): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 03:26:18.548: E/AndroidRuntime(1610): at java.lang.reflect.Method.invoke(Method.java:525)
01-15 03:26:18.548: E/AndroidRuntime(1610): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-15 03:26:18.548: E/AndroidRuntime(1610): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-15 03:26:18.548: E/AndroidRuntime(1610): at dalvik.system.NativeStart.main(Native Method)
01-15 03:26:18.548: E/AndroidRuntime(1610): Caused by: java.lang.NoSuchMethodException: manage_numbers_onClick [class android.view.View]
01-15 03:26:18.548: E/AndroidRuntime(1610): at java.lang.Class.getConstructorOrMethod(Class.java:423)
01-15 03:26:18.548: E/AndroidRuntime(1610): at java.lang.Class.getMethod(Class.java:787)
01-15 03:26:18.548: E/AndroidRuntime(1610): at android.view.View$1.onClick(View.java:3613)
01-15 03:26:18.548: E/AndroidRuntime(1610): ... 11 more
01-15 03:26:21.878: I/Choreographer(1633): Skipped 33 frames! The application may be doing too much work on its main thread.
01-15 03:26:21.898: D/gralloc_goldfish(1633): Emulator without GPU emulation detected.

这就是我在 androidmanifest 中声明的内容。

<activity
android:name="com.example.awkwardpanda_redirectcall.MainActivity"
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="com.example.awkwardpanda_redirectcall.Manage_numbers"
android:label="@string/app_name">
</activity>

最佳答案

01-14 04:40:39.458: E/AndroidRuntime(793): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.awkwardpanda_redirectcall/com.example.awkwardpanda_redirectcall.Manage_numbers}; have you declared this activity in your AndroidManifest.xml?

从上面的日志跟踪中可以清楚地看出,您尚未在 AndroidManifest 文件中声明 Manage_numbers Activity 。

<activity
android:name="com.example.awkwardpanda_redirectcall.Manage_numbers"
android:label="@string/app_name">
</activity>

在你的<application>.... </application>里面 block ...请参阅此处 better understanding

关于java - 单击 TextView 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21131430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com