我的应用程序在横向模式下崩溃

时间:2011-08-23 08:43:57

标签: java android orientation landscape

我的Android应用有问题:

我的应用是一个tabhost,有三列,两个普通视图和一个列表视图。 当我更改平板电脑的行进时,我的应用程序崩溃了。我尝试了不同的东西,我得到了一个解决方案,但它不是一个好的。

我把它放在清单中:android:configChanges="keyboardHidden|orientation"。 使用此解决方案,当我更改方向时,我的应用程序不会崩溃,但我有两个新问题,其中之一是我无法在横向模式下启动应用程序,因为如果我在平板模式下使用平板电脑我的应用程序崩溃。

另一个问题是: 我的应用程序不会将布局更改为横向。当我更改方向时,我的应用程序会自动放入正常布局但水平放置。

这是logcat输出:

08-24 09:09:56.624: ERROR/AndroidRuntime(3010): FATAL EXCEPTION: main
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.vicomtech.edonontv/org.vicomtech.edonontv.main}: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.vicomtech.edonontv/org.vicomtech.edonontv.activityDatos}: java.lang.NullPointerException
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.os.Looper.loop(Looper.java:123)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at java.lang.reflect.Method.invokeNative(Native Method)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at java.lang.reflect.Method.invoke(Method.java:521)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at dalvik.system.NativeStart.main(Native Method)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.vicomtech.edonontv/org.vicomtech.edonontv.activityDatos}: java.lang.NullPointerException
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at org.vicomtech.edonontv.main.onCreate(main.java:77)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     ... 11 more
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): Caused by: java.lang.NullPointerException
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at org.vicomtech.edonontv.activityDatos.onCreate(activityDatos.java:140)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010):     ... 19 more

和主程序:

public class main extends TabActivity {


    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

     // Create an Intent to launch an Activity for the tab (to be reused)

        intent = new Intent().setClass(this, activityPartido.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("Videos").setIndicator("Bideoak",
                          res.getDrawable(R.drawable.ic_tab_artists))
                      .setContent(intent);

        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, activityLista.class);
        spec = tabHost.newTabSpec("Sarea").setIndicator("Sarea",
                          res.getDrawable(R.drawable.ic_tab_albums))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, activityDatos.class);
        spec = tabHost.newTabSpec("Datuak").setIndicator("Datuak",
                          res.getDrawable(R.drawable.ic_tab_songs))
                    .setContent(intent);

        tabHost.addTab(spec);

        tabHost.setCurrentTab(2);

    }
}

和activityDatos的一部分:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
          setContentView(R.layout.activitydatos); 
          refresh = new RefreshHandler();
          updateUI();
private String retrieveStream(String url) {

        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(url);
        HttpResponse response = null;
        try {
            response = client.execute(request);
        } catch (ClientProtocolException e) {
            Log.w(NOTIFICATION_SERVICE, e);
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.w(NOTIFICATION_SERVICE, e);
            e.printStackTrace();
        }

        String html = "";
        InputStream in = null;
        try {
            in = response.getEntity().getContent();
        } catch (IllegalStateException e) {
            Log.w(NOTIFICATION_SERVICE, e);
            e.printStackTrace();
        } catch (IOException e) {
            Log.w(NOTIFICATION_SERVICE, e);
            e.printStackTrace();
        }
        StringBuilder str =null;
        try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        str = new StringBuilder();
        String line = null;

            while ((line = reader.readLine()) != null) {
                str.append(line);
            }
        } catch (IOException e) {
            Log.w(NOTIFICATION_SERVICE, e);
            e.printStackTrace();
        }
        try {
            in.close();
        } catch (IOException e) {
            Log.w(NOTIFICATION_SERVICE, e);
            e.printStackTrace();
        }
        html = str.toString();
        return html;

感谢一切

0 个答案:

没有答案
相关问题