English 中文(简体)
利用Twitter
原标题:Error using Twitter
  • 时间:2011-05-09 09:41:52
  •  标签:
  • android

我正在利用沉船活动的跳板,但当我们点上tw子时,它会发出集体举动。 我不知道为什么在不同的项目中采用相同的法典。 请帮助我。

Error Stack:

05-09 15:05:34.086: ERROR/AndroidRuntime(1711): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.shopzilla.android.common/org.shopzilla.android.twitter.TwitterActivity}: java.lang.ClassCastException: android.app.Application
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at android.os.Looper.loop(Looper.java:123)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at android.app.ActivityThread.main(ActivityThread.java:3683)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at java.lang.reflect.Method.invokeNative(Native Method)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at java.lang.reflect.Method.invoke(Method.java:507)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at dalvik.system.NativeStart.main(Native Method)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711): Caused by: java.lang.ClassCastException: android.app.Application
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at org.shopzilla.android.common.AbstractAsyncActivity.getApplicationContext(AbstractAsyncActivity.java:40)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at org.shopzilla.android.twitter.TwitterActivity.onCreate(TwitterActivity.java:53)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

法典:

/*
 * Copyright 2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.shopzilla.android.twitter;

import org.shopzilla.android.common.AbstractAsyncActivity;
import org.shopzilla.android.common.R;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.twitter.api.TwitterApi;
import org.springframework.social.twitter.connect.TwitterConnectionFactory;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

/**
 * @author Roy Clarkson
 */
public class TwitterActivity extends AbstractAsyncActivity 
{
    protected static final String TAG = TwitterActivity.class.getSimpleName();

    private ConnectionRepository _connectionRepository;

    private TwitterConnectionFactory _connectionFactory;


    //***************************************
    // Activity methods
    //***************************************
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.twitter_activity_layout);

        _connectionRepository = getApplicationContext().getConnectionRepository();
        _connectionFactory = getApplicationContext().getTwitterConnectionFactory();
    }

    @Override
    public void onStart() 
    {
        super.onStart();

        if (isConnected())
        {
            showTwitterOptions();
        }
        else
        {
            showConnectOption();
        }
    }


    //***************************************
    // Private methods
    //***************************************
    private boolean isConnected() 
    {
        return _connectionRepository.findPrimaryConnectionToApi(TwitterApi.class) != null;
    }

    private void disconnect()
    {
        _connectionRepository.removeConnectionsToProvider(_connectionFactory.getProviderId());
    }

    private void showConnectOption()
    {
        String[] options = {"Connect"};
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, options);
        ListView listView = (ListView) this.findViewById(R.id.twitter_activity_options_list);
        listView.setAdapter(arrayAdapter);

        listView.setOnItemClickListener(
                new AdapterView.OnItemClickListener() 
                {
                    public void onItemClick(AdapterView<?> parentView, View childView, int position, long id) 
                    {
                        switch(position)
                        {
                            case 0:
                                displayTwitterAuthorization();
                                break;
                            default:
                                break;
                        }
                    }
                }
            );
    }

    private void showTwitterOptions()
    {
        String[] options = {"Disconnect", "View Profile", "Timeline", "Tweet", "Direct Message"};
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, options);
        ListView listView = (ListView) this.findViewById(R.id.twitter_activity_options_list);
        listView.setAdapter(arrayAdapter);

        listView.setOnItemClickListener(
                new AdapterView.OnItemClickListener() 
                {
                    public void onItemClick(AdapterView<?> parentView, View childView, int position, long id) 
                    {
                        Intent intent;
                        switch(position)
                        {
                            case 0:
                                disconnect();
                                showConnectOption();
                                break;
                            case 1:
                                intent = new Intent();
                                intent.setClass(parentView.getContext(), TwitterProfileActivity.class);
                                startActivity(intent);
                                break;
                            case 2:
                                intent = new Intent();
                                intent.setClass(parentView.getContext(), TwitterTimelineActivity.class);
                                startActivity(intent);
                                break;
                            case 3:
                                intent = new Intent();
                                intent.setClass(parentView.getContext(), TwitterTweetActivity.class);
                                startActivity(intent);
                                break;
                            case 4:
                                intent = new Intent();
                                intent.setClass(parentView.getContext(), TwitterDirectMessageActivity.class);
                                startActivity(intent);
                                break;
                            default:
                                break;
                        }
                    }
                }
            );
    }

    private void displayTwitterAuthorization()
    {
        Intent intent = new Intent();
        intent.setClass(this, TwitterWebOAuthActivity.class);
        startActivity(intent);
        finish();
    }
}

摘要 Async Activities

/*
 * Copyright 2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.shopzilla.android.common;

import android.app.Activity;
import android.app.ProgressDialog;

/**
 * @author Roy Clarkson
 * @author Pierre-Yves Ricau
 */
public abstract class AbstractAsyncActivity extends Activity implements AsyncActivity
{
    protected static final String TAG = AbstractAsyncActivity.class.getSimpleName();

    private ProgressDialog _progressDialog;

    private boolean _destroyed = false;


    //***************************************
    // Activity methods
    //***************************************
    @Override
    public MainApplication getApplicationContext()
    {
        return (MainApplication) super.getApplicationContext();
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        _destroyed = true;
    }


    //***************************************
    // Public methods
    //***************************************
    public void showLoadingProgressDialog()
    {
        this.showProgressDialog("Loading. Please wait...");
    }

    public void showProgressDialog(CharSequence message)
    {
        if (_progressDialog == null)
        {
            _progressDialog = new ProgressDialog(this);
            _progressDialog.setIndeterminate(true);
        }

        _progressDialog.setMessage(message);
        _progressDialog.show();
    }

    public void dismissProgressDialog()
    {
        if (_progressDialog != null && !_destroyed)
        {
            _progressDialog.dismiss();
        }
    }
}
最佳回答

问题在于你没有显示的阶层:

05-09 15:05:34.086: ERROR/AndroidRuntime(1711): Caused by: java.lang.ClassCastException: android.app.Application
05-09 15:05:34.086: ERROR/AndroidRuntime(1711):     at org.shopzilla.android.common.AbstractAsyncActivity.getApplicationContext(AbstractAsyncActivity.java:40)

www.un.org/Depts/DGACM/index_french.htm

return (MainApplication) super.getApplicationContext();

您是否具体指明了MainApplication ,作为《roid宣言》中的应用? 否则,getApplicationContext(>>将不退还您需要的东西。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签