当我运行analize时它回来了,manafest中的一个错误android名称=不公开 但是当我构建它时说没有错误构建但是当我在我的鸸and和我的平板电脑上运行它崩溃时我无法想出来请帮助。这是我的代码,省略了名称。
activity_main.xml中
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.xxxx.xxxx.app.MainActivity"
android:background="@drawable/appbackground">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/facebook"
android:id="@+id/button1"
android:background="@drawable/facebook"
android:clickable="true"
android:enabled="true"
android:gravity="end"
android:width="50dp"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/button3"
android:layout_alignEnd="@+id/button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dealer"
android:id="@+id/button2"
android:enabled="true"
android:background="@drawable/dealer"
android:clickable="true"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/button4"
android:layout_alignStart="@+id/button4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map"
android:id="@+id/button3"
android:enabled="true"
android:clickable="true"
android:background="@drawable/google_navigation"
android:layout_below="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="29dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about"
android:id="@+id/button4"
android:enabled="true"
android:clickable="true"
android:background="@drawable/about"
android:layout_alignBottom="@+id/button3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pthdh"
android:id="@+id/button5"
android:layout_below="@+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="25dp"
android:enabled="true"
android:clickable="true"
android:background="@drawable/pthdh" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rpe"
android:id="@+id/button6"
android:layout_alignTop="@+id/button5"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:enabled="true"
android:clickable="true"
android:background="@drawable/rpebutton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/call"
android:id="@+id/button7"
android:enabled="true"
android:clickable="true"
android:background="@drawable/callus"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/contact"
android:id="@+id/button8"
android:enabled="true"
android:clickable="true"
android:background="@drawable/contact"
android:layout_marginBottom="31dp"
android:layout_above="@+id/button7"
android:layout_centerHorizontal="true" />
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textClock"
android:textStyle="bold"
android:textColor="#000000"
android:background="#ff5300"
android:gravity="center"
android:textSize="30sp"
android:textIsSelectable="true"
android:layout_above="@+id/button8"
android:layout_alignLeft="@+id/button8"
android:layout_alignStart="@+id/button8"
android:layout_marginBottom="34dp" />
</RelativeLayout>
MainActivity.java
package com.xxxx.xxxx.app;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
class MainActivity extends Activity implements OnClickListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
Button button3 = (Button) findViewById(R.id.button3);
Button button4 = (Button) findViewById(R.id.button4);
Button button5 = (Button) findViewById(R.id.button5);
Button button6 = (Button) findViewById(R.id.button6);
Button button7 = (Button) findViewById(R.id.button7);
Button button8 = (Button) findViewById(R.id.button8);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
button4.setOnClickListener(this);
button5.setOnClickListener(this);
button6.setOnClickListener(this);
button7.setOnClickListener(this);
button8.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana",
"com.facebook.katana.ProfileTabHostActivity");
Long uid = new Long("xxxx");
intent.putExtra("extra_user_id", uid);
startActivity(intent);
break;
case R.id.button2:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse
("http://www.xxxx.com"));
startActivity(intent);
break;
case R.id.button3:
Uri location = Uri.parse("geo:xx.xxx7629,-xx.xxxx584?z=14");
new Intent(Intent.ACTION_VIEW, location);
break;
case R.id.button4:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse
("http://www.xxxx.com/default.asp?page=info"));
startActivity(intent);
break;
case R.id.button5:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse
("http://www.xxxx.com/"));
startActivity(intent);
break;
case R.id.button6:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse
("https://members.xxxx.com/"));
startActivity(intent);
break;
case R.id.button7:
Intent dial = new Intent();
dial.setAction("android.intent.action.DIAL");
dial.setData(Uri.parse("tel:xxxx"));
startActivity(dial);
break;
case R.id.button8:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse
("http://www.xxxx.com/default.asp?page=xcontact"));
startActivity(intent);
break;
default:
Log.d(getApplication().getPackageName(), "Button click error!");
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
return id == R.id.action_settings || super.onOptionsItemSelected(item);
}
}
AndroidManifest xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxx.xxxx.app" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.xxxx.xxxx.app.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxx"/>
</application>
</manifest>
答案 0 :(得分:2)
你必须把公共&#34;在&#34; class&#34;之前:
public class MainActivity extends Activity implements OnClickListener