【问题标题】:Adwhril sample example giving classnotfound exceptionAdwhril 示例给出 classnotfound 异常
【发布时间】:2012-09-10 18:49:11
【问题描述】:

我的清单文件是这样的

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.basic.adwhrilsample"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
   <activity android:name=".Invoker" android:label="@string/app_name">

  <intent-filter>

    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />

  </intent-filter>

  <meta-data android:value="my sdk key"

    android:name="ADWHIRL_KEY"/>

</activity>
</application>

下面是我的 main.xml 文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:id="@+id/layout_main">

<com.adwhirl.AdWhirlLayout
    android:id="@+id/adwhirl_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

和我的 Invoker.java 活动

package com.basic.adwhrilsample;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import com.adwhirl.AdWhirlLayout;
import com.adwhirl.AdWhirlLayout.AdWhirlInterface;
import com.adwhirl.AdWhirlManager;
import com.adwhirl.AdWhirlTargeting;

public class Invoker extends Activity implements AdWhirlInterface {

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);

    AdWhirlTargeting.setAge(23);

    AdWhirlTargeting.setGender(AdWhirlTargeting.Gender.MALE);

    AdWhirlTargeting.setKeywords("online games gaming");

    AdWhirlTargeting.setPostalCode("94123");

    AdWhirlTargeting.setTestMode(false);

    AdWhirlLayout adWhirlLayout = (AdWhirlLayout)    
findViewById(R.id.adwhirl_layout);

    TextView textView = new TextView(this);

    RelativeLayout.LayoutParams layoutParams = new

    RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,

    LayoutParams.WRAP_CONTENT);

    int diWidth = 320;

    int diHeight = 52;

    int density = (int) getResources().getDisplayMetrics().density;

    adWhirlLayout.setAdWhirlInterface(this);

    adWhirlLayout.setMaxWidth((int) (diWidth * density));

    adWhirlLayout.setMaxHeight((int) (diHeight * density));

    layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

    textView.setText("Below AdWhirlLayout");

    LinearLayout layout = (LinearLayout) findViewById(R.id.layout_main);

    layout.setGravity(Gravity.CENTER_HORIZONTAL);

    layout.addView(adWhirlLayout, layoutParams);

    layout.addView(textView, layoutParams);

    layout.invalidate();

}

@Override
public void adWhirlGeneric() {

}

}

但我得到了

08-30 10:17:25.194: E/AndroidRuntime(564): java.lang.RuntimeException: Unable to     
instantiate activity   
ComponentInfo{com.basic.adwhrilsample/com.basic.adwhrilsample.Invoker}:  
java.lang.ClassNotFoundException: com.basic.adwhrilsample.Invoker in loader  
dalvik.system.PathClassLoader[/data/app/com.basic.adwhrilsample-2.apk]

谁能帮我解决我的问题。 或者任何人都可以为我提供一个示例工作示例,以便我可以遵循它

更新日志:

【问题讨论】:

  • 您是否尝试过清理项目并重新启动工作区以再次运行应用程序。
  • 那么,试试this
  • @SharathG 你在资源文件的 declare-styleable 标签中定义了 AdWhirlLayout 了吗?
  • [2012-08-30 11:02:18 - AdwhrilSample] 转换为 Dalvik 格式失败,出现错误 1。当我尝试运行它时,我在控制台中收到此错误。请给我建议。
  • @R4j 我只是在资源中做了上面的 xml 布局,没有别的。我错过了什么吗?

标签: android adwhirl


【解决方案1】:

我认为一切都很好,只需替换导入的包替换这个

 import android.widget.RelativeLayout.LayoutParams;

通过

 import android.view.ViewGroup.LayoutParams;

【讨论】:

  • [2012-08-30 11:02:18 - AdwhrilSample] 转换为 Dalvik 格式失败,出现错误 1。当我尝试运行它时,我在控制台中收到此错误。请给我建议。
  • 清理并构建您的项目
  • 转换为 Dalvik 格式失败,错误 1 ​​已解决,但我遇到的 logcat 错误与问题中的相同,请您建议我
  • 我可以提供一个工作示例,以便我可以下载并使其工作
  • @SharathG paste2.org/p/2168910 检查与粘贴单行更改的代码相同的代码
【解决方案2】:

尝试删除项目的 bin 目录,然后清理项目构建并运行。我认为您的类文件不存在于 .dex 扩展名中,有时会在文件未正确编译时发生。还要检查构建路径是否有错误。

【讨论】:

  • 你能分享完整的 logcat 输出吗?
  • 是的,上面的两个捕获是完整的 logcat 输出,接下来是重复的
  • 我只是想确保您包含的 jar 与您的类文件一起打包。如果不是,它也会导致同样的错误。
  • 是的,我包含了这个 jar 文件 AdWhirlSDK_Android_3.1.1.jar 。这够了吗?
  • 你使用哪个版本的adt插件?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-03
  • 1970-01-01
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
相关资源
最近更新 更多