切换xml布局?

时间:2012-01-18 08:31:42

标签: android android-layout android-intent

这里出了什么问题?由于某种原因,我想将xml布局从一个java类切换到另一个java类,第二个类确实有正确的代码来加载它(我相信我将在这里发布)并且应该在调用时加载但是相反我的手机一直靠近,如果你看这里我会使用意图

我现在只尝试了一个按钮

            import android.app.Activity;
      import android.content.Intent;
      import android.os.Bundle;
    import android.view.View;
     import android.view.View.OnClickListener;
       import android.widget.Button;
         import android.widget.LinearLayout;

            public class mainMenu extends Activity {
private static final int ACTIVITY_CREATE=0;

@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);  //This is calling the layout in the main.xml file if I          change the main.xml file name then I would 
       LinearLayout lin = (LinearLayout)findViewById(R.id.mainLayout);
    lin.setBackgroundResource(R.drawable.letterlist);
    Button free = (Button)findViewById(R.id.freeDraw);



    Button trace = (Button)findViewById(R.id.trace);
    Button sent = (Button)findViewById(R.id.sentence);




free.setOnClickListener(new OnClickListener() {
public void onClick (View v) {
    Intent myIntent = new Intent(v.getContext(), freeDraw.class); 
    startActivityForResult(myIntent, 0); 
}


});

}
      }

接下来将是我试图切换它的代码,它们都使用我已经检查过的相同包。

      public class freeDraw extends Activity implements OnGesturePerformedListener {
private EditText words; //calling my edit text and naming it to variable words
private static final String TAG = "Gesture Revealer"; 
GestureLibrary gestureLib = null; //calling my gesture library


@Override
       public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.free);  //This is calling the layout in trace.xml for now

任何xml文件都没有错误。所以我的问题是,我对意图做错了什么? (因为我相信这就是问题。

但基本上我想做的就是从按下按钮到主屏幕(第一个代码)时切换到自由绘图模式(第二个代码)。这带来了全新的布局。

继承了logcat中的android运行时错误

                           01-18 03:50:48.432: E/AndroidRuntime(16938): FATAL EXCEPTION: main
                           01-18 03:50:48.432: E/AndroidRuntime(16938): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.better.work.learning.letters.and.more.awesome/com.better.work.learning.letters.and.more.awesome.freeDraw}; have you declared this activity in your AndroidManifest.xml?
                      01-18 03:50:48.432: E/AndroidRuntime(16938):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)

01-18 03:50:48.432:E / AndroidRuntime(16938):at android.app.Instrumentation.execStartActivity(Instrumentation.java:1515) 01-18 03:50:48.432:E / AndroidRuntime(16938):在android.app.Activity.startActivityForResult(Activity.java:2941) 01-18 03:50:48.432:E / AndroidRuntime(16938):at com.better.work.learning.letters.and.more.awesome.mainMenu $ 1.onClick(mainMenu.java:41) 01-18 03:50:48.432:E / AndroidRuntime(16938):在android.view.View.performClick(View.java:2532) 01-18 03:50:48.432:E / AndroidRuntime(16938):在android.view.View $ PerformClick.run(View.java:9293) 01-18 03:50:48.432:E / AndroidRuntime(16938):在android.os.Handler.handleCallback(Handler.java:587) 01-18 03:50:48.432:E / AndroidRuntime(16938):在android.os.Handler.dispatchMessage(Handler.java:92) 01-18 03:50:48.432:E / AndroidRuntime(16938):在android.os.Looper.loop(Looper.java:143) 01-18 03:50:48.432:E / AndroidRuntime(16938):在android.app.ActivityThread.main(ActivityThread.java:4263) 01-18 03:50:48.432:E / AndroidRuntime(16938):at java.lang.reflect.Method.invokeNative(Native Method) 01-18 03:50:48.432:E / AndroidRuntime(16938):at java.lang.reflect.Method.invoke(Method.java:507) 01-18 03:50:48.432:E / AndroidRuntime(16938):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839) 01-18 03:50:48.432:E / AndroidRuntime(16938):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 01-18 03:50:48.432:E / AndroidRuntime(16938):at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

01-18 03:50:48.432: E/AndroidRuntime(16938): FATAL EXCEPTION: main
01-18 03:50:48.432: E/AndroidRuntime(16938): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.better.work.learning.letters.and.more.awesome/com.better.work.learning.letters.and.more.awesome.freeDraw}; have you declared this activity in your AndroidManifest.xml?
01-18 03:50:48.432: E/AndroidRuntime(16938):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)

此Logcat表示您尚未在清单文件中声明第二个活动。