首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么me.pushy.sdk.Pushy会在Eclipse中产生一个NoClassDefFoundError?

为什么me.pushy.sdk.Pushy会在Eclipse中产生一个NoClassDefFoundError?
EN

Stack Overflow用户
提问于 2015-11-01 11:21:44
回答 1查看 1.2K关注 0票数 1

我正试图在我的安卓应用程序中实现推送通知网关的推送通知,但我得到了NoClassdefFoundError。我的活动代码如下:

代码语言:javascript
复制
import java.net.URL;

import me.pushy.sdk.Pushy;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;


public class Splash extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Pushy.listen(this);
    setContentView(R.layout.activity_splash);
    new registerForPushNotificationsAsync().execute();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_splash, menu);
    return true;
}



private class registerForPushNotificationsAsync extends AsyncTask<Void, Void, Exception>
{
    protected Exception doInBackground(Void... params)
    {
        try
        {
            // Acquire a unique registration ID for this device
            String registrationId = Pushy.register(getApplicationContext());

            // Send the registration ID to your backend server and store it for later
            sendRegistrationIdToBackendServer(registrationId);
        }
        catch( Exception exc )
        {
            // Return exc to onPostExecute
            return exc;
        }

        // We're good
        return null;
    }

    @Override
    protected void onPostExecute(Exception exc)
    {
        // Failed?
        if ( exc != null )
        {
            // Show error as toast message
            Toast.makeText(getApplicationContext(), exc.toString(), Toast.LENGTH_LONG).show();
            return;
        }

        // Succeeded, do something to alert the user
    }

    // Example implementation
    void sendRegistrationIdToBackendServer(String registrationId) throws Exception
    {
        // The URL to the function in your backend API that stores registration IDs
        URL sendRegIdRequest = new URL("https://[ip]/sahiyogihaat/register.php?registration_id=" + registrationId);

        // Send the registration ID by executing the GET request
        sendRegIdRequest.openConnection();
    }
}

}

我也加了罐子..。

我的逻辑是:

不知道怎么解决这个问题..。提前谢谢你

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-01 12:18:04

在您的第一个屏幕截图中,您似乎从磁盘上的绝对路径集成了这个库,因此它可能永远不会被Android工具“DEX”编辑,因此不会成为最终APK文件的一部分。在运行时,这将导致您在屏幕快照2中描述的行为。

溶液

您需要将pushy-1.0.7.jar绑定到您的安卓应用程序中。因此,应该从从项目根目录开始的文件夹中引用相对libs。提示:不要在引用时使用“”。这可能是这里麻烦的原因。

也请参阅本文中关于处理Android项目中的依赖项的内容

项目有源文件夹,以及库项目和jar文件依赖项。除了在project.properties中将库项目作为依赖项添加之外,不需要进行其他设置,项目的类路径自动填充如下:

  • 项目的libs/*..jar的内容
  • 图书馆项目的产出。
  • 图书馆项目的libs/*..jar

..。

另一个(更通用的)概述是在Android文档/指南中找到的项目管理概述一篇文章。

来自咄咄逼人的正式文档

如果您还没有将项目迁移到Gradle,请确保在您的项目首选项中(在Eclipse / IntelliJ / Android中)中将pushy-x.jar作为一个库。确保用APK导出库。

因此,请检查pushy-1.0.7.jar文件是否放置在项目的libs文件夹中,并在类路径设置中从其中相对引用。这样它就可以工作了,构建过程应该对这些类进行DEX编译,以供以后的运行时加载。

希望能帮上忙。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33461616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档