我在我的Android手机上运行我的应用程序,它在AndroidManifest.xml
清单文件是
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sparrow.math1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="Math Quiz"
android:theme="@style/AppTheme" >
<activity
android:name="com.sparrow.math1.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.sparrow.math1.Main"
android:label="@string/app_name"
android:screenOrientation="portrait"></activity>
<activity
android:name="com.sparrow.math1.TestActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" ></activity>
<activity
android:name="com.sparrow.math1.resultActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"></activity>
<activity
android:name="com.sparrow.math1.CatagoryTest"
android:label="@string/app_name"
android:screenOrientation="portrait"></activity>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
给出此页面时出错
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
public class CatagoryTest extends Activity {
Intent intent;
DataBaseHelper dbh;
Cursor c;
ListView lst;
View v;
ArrayList<String> listItems;
ArrayAdapter<String> adapter;
BaseAdapter basea;
private AdView adView;
private static final String AD_UNIT_ID = "ca-app-pub-5660543815588540/4886657317";
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_catagory);
v=(View) findViewById(R.id.testcat);
v.setBackgroundResource(R.drawable.math);
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
LinearLayout layout = (LinearLayout) findViewById(R.id.testcat);
layout.addView(adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
adView.loadAd(adRequest);
try {
dbh=new DataBaseHelper(this.getApplicationContext());
if(dbh.createDataBase()==true){ }
dbh.openDataBase();
c=dbh.catagorydata();
c.moveToFirst();
} catch (Exception e) {
Toast.makeText(this, "Exception"+e.getMessage(),Toast.LENGTH_LONG).show();
}
try{
lst=(ListView)findViewById(R.id.catList);
listItems=new ArrayList<String>();
adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
lst.setBackgroundColor(Color.argb(150,206,206,246));
//lst.setBackgroundColor(Color.parseColor("#CECEF6"));
lst.setAdapter(adapter);
listItems.clear();
}catch(Exception e){
Toast.makeText(this, "Error : "+e.getMessage(),Toast.LENGTH_LONG).show();
}
try{
while(!c.isAfterLast()){
listItems.add(""+c.getString(0));
c.moveToNext();
adapter.notifyDataSetChanged();
}
}catch(Exception e){
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
lst.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lst.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view,int position, long id) {
int no=lst.getCheckedItemPosition();
String cat=(String) lst.getItemAtPosition(no);
Intent intent=new Intent(getApplicationContext(),com.sparrow.math1.Main.class);
intent.putExtra("category", cat);
startActivity(intent);
}
});
}
public void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
}
/** Called before the activity is destroyed. */
@Override
public void onDestroy() {
// Destroy the AdView.
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
请给我建议删除此错误。 我是android新手。请帮帮我。
答案 0 :(得分:0)
将此添加到您的清单文件中:
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
你需要声明你在清单中使用广告,它应该在那之后工作