我正在开发我的android应用程序(min sdk = 9 build = 21),我想制作一个layout-land / port和values-land / port来调整屏幕方向。当我创建这些文件夹时,应用程序崩溃并且日志指向:
final ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.blue_pressed_want)));
布局(在横向文件夹中)有这个消息(缺少样式。是否为此布局选择了正确的主题?使用布局上方的主题组合框选择不同的布局,或修复主题样式引用。在当前主题中找到样式'buttonStyle'(16个类似的错误未显示),无法解析资源@ color / grey)。
所以,我想知道如何修复它并使用我选择的操作栏的颜色。
我的logcat:
e: 04-18 10:16:56.091 27805-27805/com.nearby.myproj E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.nearby.myproj, PID: 27805
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nearby.myproj/com.myproj.projectnearby.princ.Auth}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2334)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.myproj.projectnearby.princ.Auth.onCreate(Auth.java:30)
at android.app.Activity.performCreate(Activity.java:5451)
atandroid.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
这是我的班级:
public class Auth extends FragmentActivity {
private Button btnstart,btncnxUser,btncnxAdmin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.auth);
final ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(
R.color.blue_pressed_want)));
LocationManager service = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean enabledGPS = service
.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabledGPS) {
Toast.makeText(Auth.this, "GPS signal not found", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
ConnectivityManager manager = (ConnectivityManager)getSystemService(Auth.CONNECTIVITY_SERVICE);
Boolean is3g = manager.getNetworkInfo(
ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
Boolean isWifi = manager.getNetworkInfo(
ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
if (is3g) {
Toast.makeText(Auth.this, "3G connected", Toast.LENGTH_LONG).show();
} else if (isWifi) {
Toast.makeText(Auth.this, "Wifi connected", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(Auth.this, "Network signal not found!", Toast.LENGTH_LONG).show();
// Activity transfer to wifi settings
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
}
btnstart =(Button) findViewById(R.id.btnstart);
btnstart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Auth.this, Register.class);
startActivity(intent);
}
});
btncnxUser =(Button) findViewById(R.id.btncnxuser);
btncnxUser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Auth.this, Login.class);
startActivity(intent);
}
});
btncnxAdmin =(Button) findViewById(R.id.btncnxadmin);
btncnxAdmin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Auth.this, Image.class);
startActivity(intent);
}
});
}}
auth.xml代码,在端口模式下没有问题,但在横向模式下我有这个消息(缺少样式。是否为此布局选择了正确的主题?使用布局上方的主题组合框选择不同的布局,或修复主题样式引用。无法在当前主题中找到样式'buttonStyle':
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffff" >
<ImageView
android:id="@+id/logimage"
android:layout_width="387px"
android:layout_height="180px"
android:layout_marginTop="40px"
android:src="@drawable/logo_nearby"
android:layout_centerHorizontal="true"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btnstart"
android:layout_marginTop="80px"
android:layout_centerHorizontal="true"
android:text="Start"
android:textSize="15sp"
android:layout_below="@id/logimage"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btncnxuser"
android:layout_centerHorizontal="true"
android:text="Connect as user"
android:layout_marginTop="70px"
android:textSize="15sp"
android:layout_below="@id/btnstart"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:id="@+id/txtinfo"
android:text="You have already account ?"
android:textColor="#000"
android:textSize="11sp"
android:layout_centerHorizontal="true"
android:layout_below="@id/btnstart"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btncnxadmin"
android:layout_marginTop="20px"
android:text="Connect as admin"
android:layout_centerHorizontal="true"
android:textSize="15sp"
android:layout_below="@id/btncnxuser"/>