android开发中,出现“unfortunately,项目has stopped”

lhx200610930202 2013-08-19 04:04:31
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="@style/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开发,还望各位大侠给指点一二。在这里不胜感激。
...全文
38369 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lhx200610930202 2013-08-20
  • 打赏
  • 举报
回复
我找到问题的原因了,在setTextViewColor() 中没有green_tv.setTextColor(Color.GRAY); 还有就是在constructTextView() 中也没有green_tv实例化,把这两个地方改过来就好了。不过还是要谢谢“孤独症有所好转”的热心帮助了。
lhx200610930202 2013-08-20
  • 打赏
  • 举报
回复
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_tv, layoutP); myLayout.addView(blue_tv, layoutP); myLayout.addView(cyan_tv, layoutP); myLayout.addView(dkgray_tv, layoutP); myLayout.addView(gray_tv, layoutP); myLayout.addView(red_tv, layoutP); myLayout.addView(white_tv, layoutP); } } 哎,还是找不到哪个地方存在空指针哈,各位大侠给看一下哈。多谢多谢了。
  • 打赏
  • 举报
回复
不是提示你了,空指针吗?看看哪一行。
lhx200610930202 2013-08-19
  • 打赏
  • 举报
回复
引用 1 楼 fangmingshijie 的回复:
这一般都是activity有错。在生命周期开始就挂了。
那怎么解决哦?还望指教,在线等。
  • 打赏
  • 举报
回复
这一般都是activity有错。在生命周期开始就挂了。

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧