android开发中,出现“unfortunately,项目has stopped”
LogCat 中的信息如下所示
,网上有人说要保证androidmanifest.xml配置正确,可这个一般不是自动生成的嘛,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lhx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@/AppTheme" >
<activity
android:name="com.example.lhx.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>
</application>
</manifest>
新手,刚开始学android开发,还望各位大侠给指点一二。在这里不胜感激。
,网上有人说要保证androidmanifest.xml配置正确,可这个一般不是自动生成的嘛,<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lhx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@/AppTheme" >
<activity
android:name="com.example.lhx.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>
</application>
</manifest>
新手,刚开始学android开发,还望各位大侠给指点一二。在这里不胜感激。
lhx200610930202
我找到问题的原因了,在setTextViewColor() 中没有green_tv.setTextColor(Color.GRAY);
还有就是在constructTextView() 中也没有green_tv实例化,把这两个地方改过来就好了。不过还是要谢谢“孤独症有所好转”的热心帮助了。
赞
lhx200610930202
package com.example.lhx;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.graphics.Color;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.example.lhx.R;
public class MainActivity extends Activity {
private LinearLayout myLayout;
private LinearLayout.LayoutParams layoutP;
private int WC=LinearLayout.LayoutParams.WRAP_CONTENT;
private TextView black_tv,blue_tv,cyan_tv,dkgray_tv,gray_tv,green_tv,red_tv,white_tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* 实例化一个LinearLayout布局对象*/
myLayout=new LinearLayout(this);
/*设置LinearLayout布局为垂直布局*/
myLayout.setOrientation(LinearLayout.VERTICAL);
/*设置LinearLayout布局背景图片*/
myLayout.setBackgroundResource(R.drawable.ic_launcher);
/*加载主屏布局*/
setContentView(myLayout);
/* 实例化一个LinearLayout布局参数,用来添加View*/
layoutP=new LinearLayout.LayoutParams(WC,WC);
/*构造实例化TextView*/
constructTextView();
/*把TextView添加到LinearLayout*/
addTextView();
/*设置TextView文本颜色 */
setTextViewColor();
/*设置TextView文本内容*/
setTextViewContent();
}
public void setTextViewContent() {
black_tv.setText("黑色");
blue_tv.setText("蓝色");
cyan_tv.setText("青绿色");
dkgray_tv.setText("灰黑色");
gray_tv.setText("灰色");
green_tv.setText("绿色");
red_tv.setText("红色");
white_tv.setText("白色");
}
public void setTextViewColor() {
black_tv.setTextColor(Color.BLACK);
blue_tv.setTextColor(Color.BLUE);
cyan_tv.setTextColor(Color.CYAN);
dkgray_tv.setTextColor(Color.DKGRAY);
gray_tv.setTextColor(Color.GRAY);
red_tv.setTextColor(Color.RED);
white_tv.setTextColor(Color.WHITE);
}
public void constructTextView() {
black_tv=new TextView(this);
blue_tv=new TextView(this);
cyan_tv=new TextView(this);
dkgray_tv=new TextView(this);
gray_tv=new TextView(this);
gray_tv=new TextView(this);
red_tv=new TextView(this);
white_tv=new TextView(this);
}
public void addTextView() {
myLayout.addView(black_tvlayoutP);
myLayout.addView(blue_tvlayoutP);
myLayout.addView(cyan_tvlayoutP);
myLayout.addView(dkgray_tvlayoutP);
myLayout.addView(gray_tvlayoutP);
myLayout.addView(red_tvlayoutP);
myLayout.addView(white_tvlayoutP);
}
}
哎,还是找不到哪个地方存在空指针哈,各位大侠给看一下哈。多谢多谢了。
赞
花谢尊前不敢香
不是提示你了,空指针吗?看看哪一行。
赞
lhx200610930202
那怎么解决哦?还望指教,在线等。
赞
花谢尊前不敢香
这一般都是activity有错。在生命周期开始就挂了。
赞
——到底了——
