0

我无法从mainactivity.classto移动main.class。当我单击图像视图时,它会崩溃并不幸地告诉我该应用程序已停止。

这是运行良好的主要活动:

package com.example.eateqadat;

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

public class MainActivity extends Activity {

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

         ImageView i = (ImageView)findViewById(R.id.imageView1);
            i.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    Intent explicitIntent = new Intent(MainActivity.this,main.class);
                    startActivity(explicitIntent);
                }
            });
    }
}

这是主要课程。我不知道出了什么问题,但它一直在崩溃:

package com.example.eateqadat;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class main extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = getTabHost(); 

        // Android tab
        Intent intentabout = new Intent().setClass(main.this, about.class);
        TabSpec tabSpecabout = tabHost
          .newTabSpec("Úä ÇáÈÑäÇãÌ")
          .setContent(intentabout);
        tabHost.addTab(tabSpecabout);

        tabHost.setCurrentTab(1);

    }
}

这是日志猫

01-21 17:43:23.506: E/Trace(1203): error opening trace file: No such file or directory (2)
01-21 17:43:24.117: D/dalvikvm(1203): GC_FOR_ALLOC freed 32K, 3% free 10769K/11075K, paused 42ms, total 43ms
01-21 17:43:24.126: I/dalvikvm-heap(1203): Grow heap (frag case) to 10.968MB for 376016-byte allocation
01-21 17:43:24.186: D/dalvikvm(1203): GC_FOR_ALLOC freed <1K, 3% free 11136K/11463K, paused 30ms, total 30ms
01-21 17:43:24.226: D/dalvikvm(1203): GC_FOR_ALLOC freed 0K, 3% free 11136K/11463K, paused 37ms, total 37ms
01-21 17:43:24.236: I/dalvikvm-heap(1203): Grow heap (frag case) to 11.604MB for 667348-byte allocation
01-21 17:43:24.316: D/dalvikvm(1203): GC_CONCURRENT freed 0K, 4% free 11787K/12167K, paused 18ms+3ms, total 77ms
01-21 17:43:24.316: D/dalvikvm(1203): WAIT_FOR_CONCURRENT_GC blocked 6ms
01-21 17:43:24.576: D/gralloc_goldfish(1203): Emulator without GPU emulation detected.
01-21 17:43:26.936: D/AndroidRuntime(1203): Shutting down VM
01-21 17:43:26.936: W/dalvikvm(1203): threadid=1: thread exiting with uncaught exception (group=0x2bc9a300)
01-21 17:43:26.956: E/AndroidRuntime(1203): FATAL EXCEPTION: main
01-21 17:43:26.956: E/AndroidRuntime(1203): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eateqadat/com.example.eateqadat.main}: java.lang.IllegalArgumentException: you must specify a way to create the tab indicator.
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.os.Looper.loop(Looper.java:137)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.app.ActivityThread.main(ActivityThread.java:4745)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at java.lang.reflect.Method.invokeNative(Native Method)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at java.lang.reflect.Method.invoke(Method.java:511)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at dalvik.system.NativeStart.main(Native Method)
01-21 17:43:26.956: E/AndroidRuntime(1203): Caused by: java.lang.IllegalArgumentException: you must specify a way to create the tab indicator.
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.widget.TabHost.addTab(TabHost.java:217)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at com.example.eateqadat.main.onCreate(main.java:21)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.app.Activity.performCreate(Activity.java:5008)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-21 17:43:26.956: E/AndroidRuntime(1203):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
01-21 17:43:26.956: E/AndroidRuntime(1203):     ... 11 more
01-21 17:43:29.846: I/Process(1203): Sending signal. PID: 1203 SIG: 9
4

1 回答 1

0

@user1967751 这是给你的样本

显示选项卡.xml

 <?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

 <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </TabWidget>

      <FrameLayout  
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:id="@android:id/tabcontent" >

  </FrameLayout>

   </LinearLayout>

</TabHost>

下面是AfterLoginTabActivity的代码(要调用的标签活动)

 public class AfterLoginTabActivity extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.afterloginview);
        @SuppressWarnings("deprecation")
        TabHost tabHost =getTabHost();

        Intent i = new Intent(AfterLoginTabActivity.this,ProfileClass.class);
        TabSpec profileSpec = tabHost.newTabSpec("profile").setIndicator("Profile").setContent(i);

        Intent j = new Intent(AfterLoginTabActivity.this,GroupClass.class);
        TabSpec groupSpec = tabHost.newTabSpec("group").setIndicator("group").setContent(j);

        tabHost.addTab(profileSpec);
        tabHost.addTab(groupSpec);

        tabHost.setCurrentTab(1);

    }
    }

我在 button.setOnClickListener 中使用的代码

 if(msg == "success")
    {
        System.out.println("Inside button");
        try {
            Intent intent = new Intent(MainActivity.this,AfterLoginTabActivity.class);
              startActivity(intent);
              finish(); 
          } catch (Exception e) {
               // TODO: handle exception
              System.out.print("tHIS IS EXCCEPTION" + e);
        }

    }
于 2013-06-25T11:09:49.770 回答