简体   繁体   中英

error when I try to run titanium app on android emulator

I have build an app in titanium studio and I have runned it both on iphone simulator and iphone device and it works perfectly. But when I try to run it on android emulator or android device it crashes.

I get the following error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartcrew/org.appcelerator.titanium.TiActivity}: java.lang.IllegalStateException: call to getView on a Window
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
at android.widget.TabHost.setCurrentTab(TabHost.java:323)
at android.widget.TabHost.addTab(TabHost.java:213)
at ti.modules.titanium.ui.widget.TiUITabGroup.addTab(TiUITabGroup.java:69)
at ti.modules.titanium.ui.TabGroupProxy.addTabToGroup(TabGroupProxy.java:192)
at ti.modules.titanium.ui.TabGroupProxy.handlePostOpen(TabGroupProxy.java:275)
at ti.modules.titanium.ui.TabGroupProxy.handleMessage(TabGroupProxy.java:91)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.IllegalStateException: call to getView on a Window
at ti.modules.titanium.ui.WindowProxy.getView(WindowProxy.java:63)
at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:384)
at ti.modules.titanium.ui.WindowProxy$1.windowCreated(WindowProxy.java:117)
at org.appcelerator.titanium.TiActivityWindows.windowCreated(TiActivityWindows.java:31)
at org.appcelerator.titanium.TiBaseActivity.windowCreated(TiBaseActivity.java:271)
at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:298)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

E/AndroidRuntime(  246): FATAL EXCEPTION: main
E/AndroidRuntime(  246): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartcrew/org.appcelerator.titanium.TiActivity}: java.lang.IllegalStateException: call to getView on a Window
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
at android.widget.TabHost.setCurrentTab(TabHost.java:323)
at android.widget.TabHost.addTab(TabHost.java:213)
at ti.modules.titanium.ui.widget.TiUITabGroup.addTab(TiUITabGroup.java:69)
at ti.modules.titanium.ui.TabGroupProxy.addTabToGroup(TabGroupProxy.java:192)
at ti.modules.titanium.ui.TabGroupProxy.handlePostOpen(TabGroupProxy.java:275)
at ti.modules.titanium.ui.TabGroupProxy.handleMessage(TabGroupProxy.java:91)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.IllegalStateException: call to getView on a Window
at ti.modules.titanium.ui.WindowProxy.getView(WindowProxy.java:63)
at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:384)
at ti.modules.titanium.ui.WindowProxy$1.windowCreated(WindowProxy.java:117)
at org.appcelerator.titanium.TiActivityWindows.windowCreated(TiActivityWindows.java:31)
at org.appcelerator.titanium.TiBaseActivity.windowCreated(TiBaseActivity.java:271)
at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:298)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

Has anyone any idea about what is wrong? I would post some code, but is too long and I don't know which part causes this problem.

Wait for your answers, thank you!

// this sets the background color of the master UIView (when there are no windows/tab groups on it)


//Ti.include('Window1.js');
Titanium.UI.setBackgroundColor('#000');

// create tab group


var placeHolders = [{left:10, top:10, width:20, height:20, bgColor:"#FFF", bgAlpha:0.5, img:""},
                    {left:30, top:20, width:50, height:50, bgColor:Math.random * 0xFFFFFF, bgAlpha:0.5, img:""},
                    {left:60, top:60, width:20, height:20, bgColor:Math.random * 0xFFFFFF, bgAlpha:0.5, img:""},
                    {left:100, top:20, width:20, height:20, bgColor:Math.random * 0xFFFFFF, bgAlpha:0.5, img:""},
                    {left:50, top:100, width:20, height:20, bgColor:Math.random * 0xFFFFFF, bgAlpha:0.5, img:""}
                    ];


var tabGroup = Titanium.UI.createTabGroup();





var parentWindow = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundImage:"assets/background.png",
    backgroundColor:'#fff',
    navBarHidden:true,
    tabBarHidden:true
});
addPlaceHolders();

function addPlaceHolders()
{
    for(i = 0; i < placeHolders.length; i++)
    {
        var placeHolder = placeHolders[i];
        var placeHolderView = Titanium.UI.createView({
            top:placeHolder.top,
            left:placeHolder.left,
            height:placeHolder.height,
            width:placeHolder.width,
            backgroundColor:placeHolder.bgColor,
            opacity:placeHolder.bgAlpha

        });
        placeHolderView.name = i;
        parentWindow.add(placeHolderView);
        placeHolderView.addEventListener("click", onPlaceHolderClick);
    }
}


var main = Titanium.UI.createTab({  
    title:'Tab 1',
    window:parentWindow
});
//  add tabs
tabGroup.addTab(main);  

// open tab group
tabGroup.open();

function onPlaceHolderClick(e)
{
    //tell me wot to do here
    alert("tell me wo to do here");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM