Reputation: 11
Why R file does not generate in android studio? There's no any error in xml file. When I build the project it gives error message as below.
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'. Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.
Error:Execution failed for task ':app:processDebugResources'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\admin_2\AppData\Local\Android\Sdk\build-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1
public class MainActivity extends Activity {
int counter;
Button add,sub;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button)findViewById(R.id.bAdd);
sub = (Button)findViewById(R.id.bSub);
display = (TextView)findViewById(R.id.TvDisplay);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
display.setText("Your total is" + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter--;
display.setText("Your total is" + counter);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_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
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="396dp"
android:text="your total is 0"
android:textSize="80px"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:id="@+id/TvDisplay"/>
<Button android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="add_one"
android:textSize="20dp"
android:layout_gravity="center_vertical"
android:gravity="center"
android:id="@+id/bAdd"
/>
<Button android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="subtract_one"
android:textSize="20dp"
android:gravity="center"
android:id="@+id/bSub"
/>
</LinearLayout>
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin_2.myapplication" >
<application
android:allowBackup="true"
android:icon="@mipmap/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>
</application>
</manifest>
Upvotes: 0
Views: 131
Reputation: 13541
Exactly as it sounds, R.java will not be generated if you have an error inside your xml.
The reason you have an error is because your syntax for how you're referring to that style is wrong.
It should be:
@android:style/<name>
Upvotes: 2