Android 无法安装活动组件信息(com.app/com.app.Ajax)
我在尝试运行我的应用程序时遇到此错误 请帮帮我:) 尝试打开Ajax活动的活动中的我的代码:Android 无法安装活动组件信息(com.app/com.app.Ajax),android,Android,我在尝试运行我的应用程序时遇到此错误 请帮帮我:) 尝试打开Ajax活动的活动中的我的代码: package com.app; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ImageButton; public class Champions extends Ac
package com.app;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class Champions extends Activity{
ImageButton ajax,arsenal,barca,bayern,chelsea,cska,dortmund,gala,inter,juve,leverkusen,milan,porto,psg,psv,real,schalke,united,valencia,zenit;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.champions);
initialize();
ajax.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent ajax1=new Intent(Champions.this,Ajax.class);
startActivity(ajax1);
}
});
}
private void initialize() {
// TODO Auto-generated method stub
ajax = (ImageButton) findViewById(R.id.IBajax);
arsenal = (ImageButton) findViewById(R.id.IBarsenal);
barca = (ImageButton) findViewById(R.id.IBbarca);
bayern = (ImageButton) findViewById(R.id.IBbayern);
chelsea = (ImageButton) findViewById(R.id.IBchelsea);
cska = (ImageButton) findViewById(R.id.IBcska);
dortmund = (ImageButton) findViewById(R.id.IBdortmund);
gala = (ImageButton) findViewById(R.id.IBgala);
inter = (ImageButton) findViewById(R.id.IBinter);
juve = (ImageButton) findViewById(R.id.IBjuve);
leverkusen = (ImageButton) findViewById(R.id.IBleverkusen);
milan = (ImageButton) findViewById(R.id.IBmilan);
porto = (ImageButton) findViewById(R.id.IBporto);
psg = (ImageButton) findViewById(R.id.IBpsg);
psv = (ImageButton) findViewById(R.id.IBpsv);
real = (ImageButton) findViewById(R.id.IBreal);
schalke = (ImageButton) findViewById(R.id.IBschalke);
united = (ImageButton) findViewById(R.id.IBunited);
valencia = (ImageButton) findViewById(R.id.IBvalencia);
zenit = (ImageButton) findViewById(R.id.IBzenit);
}
}
还有我的舱单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.app.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.app.Play"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.app.Champions"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.app.Ajax"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.actionAJAX" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.app.Stats"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
我需要为应用程序运行做什么
Ajax.java:
package com.app;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Ajax extends Activity{
TextView TVajax;
Context context = getApplicationContext();
Button hint1,hint2,check,used,right;
EditText answer;
Button stats;
public static boolean right(String[] a,String b)
//in=String array and string
//out=if the string is equal/close to one of the strings in the array-true else-false
{
boolean flag=false;
for(int i=0;i<a.length;i++)
{
int count=0;
if(a[i].length()==b.length()){
if(a[i].equalsIgnoreCase(b))
return true;
else{if(a[i].length()>6){
for(int j=0;j<a[i].length();j++)
{
if(a[i].charAt(j)==b.charAt(j))
count++;
}
if(count==a[i].length()-1)
flag=true;
}
}
}
}
return flag;
}
public void messageBox(String[] a,String b,String answer,TextView tv,int points)
//in=get the answer of the "right" method and the present name
//out=if true-change the "TVajax" to the present name and pop up a message; false-nothing
{
boolean f=false;
if(right(a,b))
{
tv.setText(answer);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("points: "+points);
builder.setTitle("Perfect!");
AlertDialog dialog = builder.create();
builder.setPositiveButton(R.id.bStats, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent stats=new Intent(Ajax.this,Stats.class);
startActivity(stats);
}
});
builder.setNegativeButton(R.id.bBack, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
finish();
}
});
}
else{
if(b.length()<=6){
for(int i=0;i<a.length&&!f;i++)
{
int fl=-1;
int count=0;
int diff=a[i].length()-b.length();
switch(diff){
case 0:
for(int j=0;j<a[i].length();j++)
{
if(a[i].charAt(j)==b.charAt(j))
count++;
if(count==a[i].length()-1){
f=true;
CharSequence text = "Almost perfect,you'r close!";
int duration = Toast.LENGTH_SHORT;
Toast popuptoast=Toast.makeText(context, text, duration);
popuptoast.show();
}
}
break;
case 1:
if(a[i].startsWith(b)||a[i].endsWith(b)){
f=true;
CharSequence text = "Almost perfect,you'r close!";
int duration = Toast.LENGTH_SHORT;
Toast popuptoast=Toast.makeText(context, text, duration);
popuptoast.show();
}
break;
case -1:
if(b.startsWith(a[i])||b.endsWith(a[i])){
f=true;
CharSequence text = "Almost perfect,you'r close!";
int duration = Toast.LENGTH_SHORT;
Toast popuptoast=Toast.makeText(context, text, duration);
popuptoast.show();
}
else{
for(int j=1;j<a[i].length()&&fl==-1;j++)
{
if(a[i].charAt(j)!=b.charAt(j)&&a[i].charAt(j)==b.charAt(j+1)){
fl=j;
if(a[i].substring(0, j).equalsIgnoreCase(b.substring(0, j))&&a[i].substring(j).equalsIgnoreCase(b.substring(j+1))){
f=true;
CharSequence text = "Almost perfect,you'r close!";
int duration = Toast.LENGTH_SHORT;
Toast popuptoast=Toast.makeText(context, text, duration);
popuptoast.show();
}
}
}
}
default:;
}
}
}else{
for(int i=0;i<a.length&&!f;i++)
{
int fm=-1,sm=-1;
int diff=a[i].length()-b.length();
int count=0;
switch(diff){
case 0:
for(int j=0;j<a[i].length();j++)
{
if(a[i].charAt(j)==b.charAt(j))
count++;
if(count==a[i].length()-2){
f=true;
CharSequence text = "Almost perfect,you'r close!";
int duration = Toast.LENGTH_SHORT;
Toast popuptoast=Toast.makeText(context, text, duration);
popuptoast.show();
}
}
break;
case 1:
if(b.startsWith(a[i])||b.endsWith(a[i])){
f=true;
CharSequence text = "Almost perfect,you'r close!";
int duration = Toast.LENGTH_SHORT;
Toast popuptoast=Toast.makeText(context, text, duration);
popuptoast.show();
}
break;
case 2:
if(a[i].indexOf(b)!=-1){
f=true;
CharSequence text = "Almost perfect,you'r close!";
int duration = Toast.LENGTH_SHORT;
Toast popuptoast=Toast.makeText(context, text, duration);
popuptoast.show();
}
break;
case -1:
for(int j=0;j<a[i].length()&&(fm==-1||sm==-1);j++)
{
if(a[i].charAt(j)!=b.charAt(j)&&fm==-1)
fm=j;
if(a[i].charAt(j)!=b.charAt(j)&&fm!=-1)
sm=j;
}
if(b.substring(0,fm).equalsIgnoreCase(a[i].substring(0, fm))&&b.substring(fm+1, sm).equalsIgnoreCase(a[i].substring(fm, sm))&&b.substring(sm+1).equalsIgnoreCase(a[i].substring(sm))){
f=true;
CharSequence text = "Almost perfect,you'r close!";
int duration = Toast.LENGTH_SHORT;
Toast popuptoast=Toast.makeText(context, text, duration);
popuptoast.show();
}
break;
case -2:
if(b.indexOf(a[i])!=-1){
f=true;
CharSequence text = "Almost perfect,you'r close!";
int duration = Toast.LENGTH_SHORT;
Toast popuptoast=Toast.makeText(context, text, duration);
popuptoast.show();
}
break;
}
}
}
if(!f){
CharSequence text = "wrong answer,try again!";
int duration = Toast.LENGTH_SHORT;
Toast popuptoast=Toast.makeText(context, text, duration);
popuptoast.show();
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.ajax);
initialize();
check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String[] answers={"amsterdamsche football club ajax nv","ajax","afc","afc ajax","afc ajax amsterdam","amsterdam","ajax amsterdam","ajax afc","ajax amsterdam afc","afc amsterdam","amsterdam ajax afc","amsterdam ajax"};
answer = (EditText) findViewById(R.id.ETajax);
String answera=answer.getText().toString();
}
});
}
private void initialize() {
// TODO Auto-generated method stub
TVajax= (TextView) findViewById(R.id.TVajax);
hint1 = (Button) findViewById(R.id.Hint1);
hint2 = (Button) findViewById(R.id.Hint2);
check = (Button) findViewById(R.id.Bcheck);
right = (Button) findViewById(R.id.BshowLetters);
used = (Button) findViewById(R.id.BusedLetters);
stats = (Button) findViewById(R.id.bStats);
}
}
package.com.app;
导入android.app.Activity;
导入android.app.AlertDialog;
导入android.content.Context;
导入android.content.DialogInterface;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.TextView;
导入android.widget.Toast;
公共类Ajax扩展了活动{
TextView-TVajax;
Context=getApplicationContext();
按钮铰链1,铰链2,检查,已使用,右侧;
编辑文本回答;
按钮统计;
公共静态布尔权限(字符串[]a,字符串b)
//in=字符串数组和字符串
//out=如果字符串等于/接近数组中的一个字符串,则为true,否则为false
{
布尔标志=假;
对于(int i=0;i6){
对于(intj=0;j,您必须调用您的意图
ajax
和您的imagebutton同名
更改意图的名称可能会很好。您不能像这样初始化按钮按钮stats=(button)findViewById(R.id.bStats);
这会尝试初始化字段,但当活动被实例化时,它仍然没有contentView
像其他对象一样初始化初始化方法中的按钮。看起来在Ajax.java
的第18行有一个NullPointerException
。你能粘贴它吗?我添加了Ajax.java这是Ajax.java:Context Context=getApplicationContext()上的第18行;这里会出现什么问题?我解决了问题!感谢所有试图帮助我的人!我在初始化方法中初始化了按钮,但没有帮助..我将在帖子中编辑Ajax.java。在Ajax.java更改后,我将日志更改为新日志。在您的回答下,经过思考,我发现了问题!我必须更改日志ne'Context Context=getApplicationContext();'to'Context Context;'并将'Context=getApplicationContext;'行添加到“messageBox”方法的第一行。非常感谢您!
ajax