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>
答案 0 :(得分:2)
01-14 04:40:39.458:E / AndroidRuntime(793):引起: android.content.ActivityNotFoundException:无法找到显式 活动课 {com.example.awkwardpanda_redirectcall / com.example.awkwardpanda_redirectcall.Manage_numbers}; 你有没有在AndroidManifest.xml中声明这个活动?
从上面的日志跟踪中可以看出,你没有在AndroidManifest文件中声明Manage_numbers活动。
<activity
android:name="com.example.awkwardpanda_redirectcall.Manage_numbers"
android:label="@string/app_name">
</activity>
在<application>.... </application>
区块内...请参阅此处better understanding
答案 1 :(得分:1)
清单中是否定义了Manage_numbers.class
?它不是空的吗?
您是否在MainActivity中夸大了正确的布局?
您需要发布logcat以获得更好的特定答案。