对,我卡住了,非常困惑。我已经创建了一个应用程序,它可以在其他方面正常工作,但是我在几个页面中遇到按钮问题。
我从已知工作的页面复制了java和xml。但它没有解决问题。如果我从java文件中取出所有按钮,它将编译并运行并加载页面。
但是,如果我将按钮文本(与其他所有页面一起使用)放回其中,则在我开始活动时不会加载页面
这是错误日志
05-09 13:19:33.724: D/AndroidRuntime(896): Shutting down VM
05-09 13:19:33.724: W/dalvikvm(896): threadid=1: thread exiting with uncaught exception (group=0x2bc9a300)
05-09 13:19:33.735: E/AndroidRuntime(896): FATAL EXCEPTION: main
05-09 13:19:33.735: E/AndroidRuntime(896): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.british.sheep/com.british.sheep.mix}; have you declared this activity in your AndroidManifest.xml?
05-09 13:19:33.735: E/AndroidRuntime(896): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
05-09 13:19:33.735: E/AndroidRuntime(896): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
05-09 13:19:33.735: E/AndroidRuntime(896): at android.app.Activity.startActivityForResult(Activity.java:3351)
05-09 13:19:33.735: E/AndroidRuntime(896): at android.app.Activity.startActivityForResult(Activity.java:3312)
05-09 13:19:33.735: E/AndroidRuntime(896): at com.british.sheep.colour$4.onClick(colour.java:62)
05-09 13:19:33.735: E/AndroidRuntime(896): at android.view.View.performClick(View.java:4084)
05-09 13:19:33.735: E/AndroidRuntime(896): at android.view.View$PerformClick.run(View.java:16966)
05-09 13:19:33.735: E/AndroidRuntime(896): at android.os.Handler.handleCallback(Handler.java:615)
05-09 13:19:33.735: E/AndroidRuntime(896): at android.os.Handler.dispatchMessage(Handler.java:92)
05-09 13:19:33.735: E/AndroidRuntime(896): at android.os.Looper.loop(Looper.java:137)
05-09 13:19:33.735: E/AndroidRuntime(896): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-09 13:19:33.735: E/AndroidRuntime(896): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:19:33.735: E/AndroidRuntime(896): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 13:19:33.735: E/AndroidRuntime(896): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-09 13:19:33.735: E/AndroidRuntime(896): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-09 13:19:33.735: E/AndroidRuntime(896): at dalvik.system.NativeStart.main(Native Method)
就像我说我知道按钮代码的工作方式,因为我已经完美地将它用于许多其他应用程序。所以我卡住了。当我添加按钮时,其余代码就可以正常工作。
这可能是什么
public class creamy extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//makes full screen and takes away title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//
setContentView(R.layout.creamy);
Button wensleydale = (Button) findViewById(R.id.wensleydale);
wensleydale.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), wensleydale.class);
startActivityForResult(myIntent, 0);
}
});
}
//code for menu add to all pages
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.text: Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
break;
case R.id.cat:
startActivity(new Intent(getApplicationContext(), creamy.class));
break;
case R.id.ato:
startActivity(new Intent(getApplicationContext(), atoz.class));
break;
}
return true;
}
//end code for menu
}
这是活动代码,除了类名和设置内容视图布局外,它与我知道的其他活动相同
答案 0 :(得分:1)
在清单中声明您的活动
<activity android:name="com.british.sheep.mix" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
答案 1 :(得分:0)
在android清单文件中添加wensleydale.class
:
<activity android:name=".wensleydale"/>
如果您已经声明,请尝试使用包名称:
<activity android:name="com.test.wensleydale"/>
无论您的包裹名称是什么。