在eclipse中没有红色错误,但是当我尝试运行应用程序时,它说不幸的是按钮停止了。
logcat的
11-09 10:13:33.134: D/AndroidRuntime(1007): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
11-09 10:13:33.144: D/AndroidRuntime(1007): CheckJNI is ON
11-09 10:13:33.184: D/dalvikvm(1007): Trying to load lib libjavacore.so 0x0
11-09 10:13:33.204: D/dalvikvm(1007): Added shared lib libjavacore.so 0x0
11-09 10:13:33.264: D/dalvikvm(1007): Trying to load lib libnativehelper.so 0x0
11-09 10:13:33.264: D/dalvikvm(1007): Added shared lib libnativehelper.so 0x0
11-09 10:13:34.124: D/AndroidRuntime(1007): Calling main entry com.android.commands.pm.Pm
11-09 10:13:34.184: D/AndroidRuntime(1007): Shutting down VM
11-09 10:13:34.204: D/dalvikvm(1007): GC_CONCURRENT freed 101K, 78% free 466K/2048K, paused 1ms+1ms, total 15ms
11-09 10:13:34.204: D/dalvikvm(1007): Debugger has detached; object registry had 1 entries
11-09 10:13:34.815: D/AndroidRuntime(1020): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
11-09 10:13:34.815: D/AndroidRuntime(1020): CheckJNI is ON
11-09 10:13:34.884: D/dalvikvm(1020): Trying to load lib libjavacore.so 0x0
11-09 10:13:34.904: D/dalvikvm(1020): Added shared lib libjavacore.so 0x0
11-09 10:13:34.964: D/dalvikvm(1020): Trying to load lib libnativehelper.so 0x0
11-09 10:13:34.964: D/dalvikvm(1020): Added shared lib libnativehelper.so 0x0
11-09 10:13:36.064: D/AndroidRuntime(1020): Calling main entry com.android.commands.am.Am
11-09 10:13:36.134: I/ActivityManager(151): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.bogdanskoric.button/.MainActivity u=0} from pid 1020
11-09 10:13:36.144: W/WindowManager(151): Failure taking screenshot for (246x410) to layer 21005
11-09 10:13:36.194: D/dalvikvm(1030): Not late-enabling CheckJNI (already on)
11-09 10:13:36.204: D/AndroidRuntime(1020): Shutting down VM
11-09 10:13:36.224: I/AndroidRuntime(1020): NOTE: attach of thread 'Binder_3' failed
11-09 10:13:36.244: D/dalvikvm(1020): GC_CONCURRENT freed 102K, 77% free 489K/2048K, paused 6ms+1ms, total 29ms
11-09 10:13:36.254: I/ActivityManager(151): Start proc com.bogdanskoric.button for activity com.bogdanskoric.button/.MainActivity: pid=1030 uid=10046 gids={1028}
11-09 10:13:36.254: D/jdwp(1020): Got wake-up signal, bailing out of select
11-09 10:13:36.254: D/dalvikvm(1020): Debugger has detached; object registry had 1 entries
11-09 10:13:36.334: I/Choreographer(248): Skipped 43 frames! The application may be doing too much work on its main thread.
11-09 10:13:36.714: E/Trace(1030): error opening trace file: No such file or directory (2)
11-09 10:13:37.234: I/Choreographer(248): Skipped 104 frames! The application may be doing too much work on its main thread.
11-09 10:13:37.324: D/AndroidRuntime(1030): Shutting down VM
11-09 10:13:37.324: W/dalvikvm(1030): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
11-09 10:13:37.344: E/AndroidRuntime(1030): FATAL EXCEPTION: main
11-09 10:13:37.344: E/AndroidRuntime(1030): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bogdanskoric.button/com.bogdanskoric.button.MainActivity}: java.lang.RuntimeException: Binary XML file line #11: You must supply a layout_width attribute.
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.os.Looper.loop(Looper.java:137)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-09 10:13:37.344: E/AndroidRuntime(1030): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 10:13:37.344: E/AndroidRuntime(1030): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 10:13:37.344: E/AndroidRuntime(1030): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-09 10:13:37.344: E/AndroidRuntime(1030): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-09 10:13:37.344: E/AndroidRuntime(1030): at dalvik.system.NativeStart.main(Native Method)
11-09 10:13:37.344: E/AndroidRuntime(1030): Caused by: java.lang.RuntimeException: Binary XML file line #11: You must supply a layout_width attribute.
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5458)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5594)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.widget.RelativeLayout$LayoutParams.<init>(RelativeLayout.java:1099)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:956)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:70)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.view.LayoutInflater.rInflate(LayoutInflater.java:748)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-09 10:13:37.344: E/AndroidRuntime(1030): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.app.Activity.setContentView(Activity.java:1867)
11-09 10:13:37.344: E/AndroidRuntime(1030): at com.bogdanskoric.button.MainActivity.onCreate(MainActivity.java:22)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.app.Activity.performCreate(Activity.java:5008)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-09 10:13:37.344: E/AndroidRuntime(1030): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-09 10:13:37.344: E/AndroidRuntime(1030): ... 11 more
11-09 10:13:37.364: W/ActivityManager(151): Force finishing activity com.bogdanskoric.button/.MainActivity
11-09 10:13:37.374: W/WindowManager(151): Failure taking screenshot for (246x410) to layer 21010
11-09 10:13:37.894: W/ActivityManager(151): Activity pause timeout for ActivityRecord{4159fd60 com.bogdanskoric.button/.MainActivity}
11-09 10:13:38.234: I/Choreographer(248): Skipped 36 frames! The application may be doing too much work on its main thread.
MainActivty
package com.bogdanskoric.button;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity implements View.OnClickListener
{
Button buttonE;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonE = (Button) findViewById(R.id.button);
buttonE.setOnClickListener (this);
}
private void buttonClick ()
{
startActivity(new Intent ("com.bogdanskoric.button.EmocijeActivityMainActivity"));
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.button:
buttonClick();
break;
}
}
}
activity_main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.bogdanskoric.button.MainActivity" >
<TextView
/>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="33dp"
android:layout_marginTop="42dp"
android:text="@string/button"
/>
</RelativeLayout>
EmocijeActivityMainActivity
package com.bogdanskoric.button;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class EmocijeActivityMainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.emocije_activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.emocije_activity_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
按钮清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bogdanskoric.button"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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=".EmocijeActivityMainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.bogdanskoric.button.EmocijeActivityMainActivity" />
<category android:name="android.intent.category.DEFOULT" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:1)
错误说明了一切:二进制XML文件行#11:您必须提供layout_width
属性。
基本上错误是你没有在TextView的xml属性中定义任何layout_width
和layout_height
...
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
... Other Attributes
/>