Unable to start activity ComponentInfo{com.example.hellotest/com.example.hellotest.TypefaceActivity}
来源:互联网 发布:俄罗斯老婆知乎 编辑:程序博客网 时间:2024/06/05 18:48
09-24 11:28:04.471: E/AndroidRuntime(26563): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hellotest/com.example.hellotest.TypefaceActivity}: java.lang.IllegalArgumentException: generateDefaultLayoutParams() cannot return null
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1957)
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1982)
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.app.ActivityThread.access$600(ActivityThread.java:124)
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1148)
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.os.Handler.dispatchMessage(Handler.java:99)
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.os.Looper.loop(Looper.java:137)
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.app.ActivityThread.main(ActivityThread.java:4456)
09-24 11:28:04.471: E/AndroidRuntime(26563): at java.lang.reflect.Method.invokeNative(Native Method)
09-24 11:28:04.471: E/AndroidRuntime(26563): at java.lang.reflect.Method.invoke(Method.java:511)
09-24 11:28:04.471: E/AndroidRuntime(26563): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-24 11:28:04.471: E/AndroidRuntime(26563): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-24 11:28:04.471: E/AndroidRuntime(26563): at dalvik.system.NativeStart.main(Native Method)
09-24 11:28:04.471: E/AndroidRuntime(26563): Caused by: java.lang.IllegalArgumentException: generateDefaultLayoutParams() cannot return null
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.view.ViewGroup.addView(ViewGroup.java:3162)
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.view.ViewGroup.addView(ViewGroup.java:3145)
09-24 11:28:04.471: E/AndroidRuntime(26563): at com.example.hellotest.TypefaceActivity.onCreate(TypefaceActivity.java:35)
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.app.Activity.performCreate(Activity.java:4465)
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051)
09-24 11:28:04.471: E/AndroidRuntime(26563): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1921)
09-24 11:28:04.471: E/AndroidRuntime(26563): ... 11 more
代码如下:
package com.example.hellotest;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
public class TypefaceActivity extends Activity{
private LinearLayout layout;
private LinearLayout.LayoutParams layoutParams;
private int WRAP_CONTENT = LinearLayout.LayoutParams.WRAP_CONTENT;
private TextView textView_style;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
layout = new LinearLayout(this);
// layout.setBackgroundResource(R.drawable.qq1);
layout.setOrientation(WRAP_CONTENT);
layout.setBackgroundColor(Color.GREEN);
setContentView(layout);
layoutParams = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
textView_style = new TextView(this);
textView_style.setText("style");
textView_style.setTextColor(Color.BLUE);
textView_style.setTextSize(24.0f);//设置绘制的文本大小,值为浮点类型
textView_style.setTypeface(null, Typeface.BOLD);//设置字体风格
layout.addView(textView_style);
}
}
原因:获取主屏布局参数为空
修改:将layout.setOrientation(WEAP_CONTENT)改成layout.setOrientation(LinearLayout.VERTICAL).
- Unable to start activity ComponentInfo{com.example.hellotest/com.example.hellotest.TypefaceActivity}
- Android问题1: Unable to start activity ComponentInfo{com.example.demo/com.example.demo
- Unable to start activity ComponentInfo{com.example.customview/com.example.customview.MainActivity}:
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.FirstView/com.example
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.w/com.example.w.MainA
- Unable to start activity ComponentInfo{com.example.activity02/com.example.activity02.otheractivity}:
- Unable to start activity ComponentInfo{com.example.test/com.example.test.DividiDemoActivity
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xiaoshuo01/com.exampl
- 错误:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tongzhi
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bingbing.littlefarmer
- java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.irun/com.exampl
- java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.AndroidCaptureC
- Unable to start activity ComponentInfo{com.first/com.first.Game}
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.clm.activity/com.clm.activity
- java.lang.RuntimeException: Unable to start activity ComponentInfo{ com.xuqinjun.hello01/com.xuqinj
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wwj.toggle/com.wwj.toggle.Set
- java.lang.RuntimeException:Unable to start activity ComponentInfo{com.meizu.beautify/com.my.viewc.Ma
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.esri.arcgis.android.samples.h
- 批量图片格式与尺寸转换
- 02_对N个长度最长可达到1000的数进行排序、对给定的一个字符串,找出有重复的字符,并给出其位置、输入一系列整数,将其中最大的数挑出,并将剩下的数进行排序
- while循环
- 一个获取dll导出函数的模板类
- 2013.09.04更新——【Firefly API 新版文档】Package dbentrust
- Unable to start activity ComponentInfo{com.example.hellotest/com.example.hellotest.TypefaceActivity}
- 神清气爽,小妹妹,先给她示范了一遍红色警戒
- 怎么做一个优秀的休闲食品代理商
- java 操作excel 导入数据库
- CLR via C#(第3版).pdf 清晰版.带自己整的 目录
- 向自定义工作流活动添加属性并获得属性的值
- linux中怎样关闭ICMP回应功能
- mysql 在多个表中查询同一个值
- select * from a,b 的弊端和代替方案