Unable to instantiate activity ComponentInfo{ProductSimpleInfoActivity} NullPointerException - java

this is my manifest files:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iadmo.dahan"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal"
>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:name="com.iadmo.dahan.application.MyApplication"
android:icon="#drawable/appicon"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name="com.iadmo.dahan.activity.WelcomeActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:clearTaskOnLaunch="false"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.RecommendActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.PersonalActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.LoginActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.RegisterActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.DownloadedActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.SortedActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ClassesActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.SearchedActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductDetailsActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.PerClassActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductCommentActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductSimpleInfoActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.CommentDetailsActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.DownloadingActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<service android:name="com.iadmo.dahan.service.DownloadService"/>
</application>
and this is the xml for layout of productdetailsActivity:
public class ProductDetailsActivity extends TabActivity {
private TabHost mHost;
private String appId, userId;
private ListView per_class_simple_info;
private List<BaseInfo> datas;
private DetailsAdapter adapter;
private TextView txtview1, txtview2;
private Button back;
private TextView title_name;
private Dialog dialog;
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_productdetail);
MyApplication.getInstance().addActivity(this);
Bundle bundle = getIntent().getExtras();
appId = bundle.getString("appId");
userId = AppUtil.getString(getApplicationContext(), "userid", "");
initCompanents();
initViews();
initDatas();
Intent intent = new Intent();
intent.setAction("GOODID");
intent.putExtras(bundle);
getApplicationContext().sendBroadcast(intent);
initEvents();
}
#SuppressWarnings("deprecation")
private void initViews() {
back = (Button) findViewById(R.id.back);
title_name = (TextView) findViewById(R.id.title_name);
per_class_simple_info = (ListView) findViewById(R.id.per_class_simple_info);
mHost = this.getTabHost();
mHost.addTab(mHost.newTabSpec("mhost_job").setIndicator(txtview1)
.setContent(new Intent(this, ProductSimpleInfoActivity.class)));
mHost.addTab(mHost.newTabSpec("mhost_company").setIndicator(txtview2)
.setContent(new Intent(this, ProductCommentActivity.class)));
}
private void initCompanents() {
txtview1 = new TextView(this);
txtview1.setText("简介");
txtview1.setTextColor(getResources().getColor(R.color.white));
txtview1.setGravity(Gravity.CENTER);// 文字居中
txtview1.setTextSize(15);// 字体大小
txtview1.setPadding(15, 16, 15, 15);// 四周填充
txtview1.setBackgroundResource(R.drawable.tabhost_bg);
txtview2 = new TextView(this);
txtview2.setText("评论");
txtview2.setTextColor(getResources().getColor(R.color.black));
txtview2.setGravity(Gravity.CENTER);// 居中
txtview2.setTextSize(15);// 字体大小
txtview2.setPadding(15, 16, 15, 15);// 填充
txtview2.setBackgroundResource(R.drawable.tabhost_bg);
LayoutParams param1 = new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
param1.setMargins(0, 10, 0, 0);
param1.weight = 1;// 权重
txtview1.setLayoutParams(param1);
LayoutParams param2 = new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
param2.setMargins(0, 10, 0, 0);
param2.weight = 1;// 权重
txtview2.setLayoutParams(param2);
}
and this is the productSimpleInfoActivity's code:
public class ProductSimpleInfoActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simpleinfo);
MyApplication.getInstance().addActivity(this);
initViews();
registerReceivers();
initEvents();
}
this is the productDetail xml layout,i think this is right ,i tired it ,it worked,but today i tired again,it failed:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
</TabWidget>
<View
android:layout_width="fill_parent"
android:layout_height="#dimen/s_5"
android:background="#color/red_light" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>

Try the following code.It hopefully works.
main.xml file :
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/tabhost" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"></FrameLayout>
</LinearLayout>
</TabHost>
In Class File add this code in your onCreate():
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, Personal.class);
spec = tabHost.newTabSpec("personal").setIndicator("Personal").setContent(intent);
tabHost.addTab(spec);

Related

App showing a blank screen but Preview looks fine

So I've tried to write an application that saves relatively high-quality images but when I start the app in an emulator or my phone, it only shows a blank screen. In the Preview, it looks like it should look.
I have little experience in Java. Not much tho. I've tried a few things like changing the layout or what is displayed but nothing really worked or made any difference.
This is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cameraexample">
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".DisplayImage">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:authorities="com.example.android.fileprovider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_path" />
</provider>
</application>
</manifest>
This is the activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
tools:context=".MainActivity">
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="#string/capture_image"
android:onClick="captureImage"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="#string/display_image"
android:onClick="displayImage"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
This is activity_main source code:
public class MainActivity extends AppCompatActivity {
String currentImagePath = null;
private static final int IMAGE_REQUEST = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void captureImage(View view) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(cameraIntent.resolveActivity(getPackageManager()) != null){
File imageFile = null;
try {
imageFile = getImageFile();
}
catch (IOException e) {
e.printStackTrace();
}
if(imageFile != null) {
Uri imageUri = FileProvider.getUriForFile(this, "com.example.android.fileprovider", imageFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, IMAGE_REQUEST);
}
}
}
public void displayImage(View view) {
Intent intent = new Intent(this, DisplayImage.class);
intent.putExtra("image_path", currentImagePath);
startActivity(intent);
}
private File getImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
String imageName = "jps_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File imageFile = File.createTempFile(imageName, ".jpg", storageDir);
currentImagePath = imageFile.getAbsolutePath();
return imageFile;
}
}
This is the activity_display_image.xml:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".DisplayImage">
<ImageView
android:contentDescription="#string/bild_ansicht"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
android:id="#+id/mimageView"/>
</RelativeLayout>
And last but not least, it's source code:
public class DisplayImage extends AppCompatActivity {
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_image);
imageView = findViewById(R.id.mimageView);
Bitmap bitmap = BitmapFactory.decodeFile(getIntent().getStringExtra("image_path"));
imageView.setImageBitmap(bitmap);
}
}
There are no error messages. I want those buttons to show up. The rest should work just fine.
It seems like that the multiple MAIN entry points are confusing your opening of the app.
Make sure you are opening the app from the correct launcher icon.
You should see two icons from the same app in your launcher. There might be a blank layout for the DisplayImage Activity which you are opening. Thus the blank screen.
I am referring to these in the manifest file
<activity android:name=".DisplayImage">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I am also not that experienced with Android but have you tried removing the intent filter for DisplayImage in your manifest?
You have two activities with this defined :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
That tells Android that it can launch the application from either of them and since DisplayImage is declared first in the manifest, what you are seeing is an empty blank screen as no image has yet been loaded from MainActivity.
Check this out so that you have a better understanding of intents and intent filter
https://developer.android.com/guide/components/intents-filters

My app crashes when I clicked the Imagebutton instead of taking me to another Activity

I'm making an android app on Android Studio. And I come out with a problem . When I click my ImageButton the app crashes instead of going to a new activity (Slide1)...
I dont know where I got it wrong .
Here is my MainActivity.java
package android.example.ptreinas;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.content.Intent;
public class MainActivity extends AppCompatActivity {
private ImageButton imageButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
openSlide1();
}
});
}
public void openSlide1(){
Intent intent = new Intent(this, Slide1.class);
startActivity(intent);
}
}
and my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:gravity="center"
tools:context=".MainActivity"
android:background="#color/red">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="400px"
android:layout_gravity="center"
android:src="#drawable/gym" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Programa de treinos "
android:layout_gravity="center"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="80px"
android:layout_marginTop="50px"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Escolha o programa de treino mais adequado aos seus objetivos."
android:layout_gravity="center"
android:textAlignment="center"
android:layout_marginTop="50px"
android:textSize="50px"
android:textColor="#ffffff"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:src="#drawable/ic_right"
android:background="#drawable/roundcorner"
android:padding="50px"
android:layout_gravity="center"
android:layout_marginTop="150px"
/>
</LinearLayout>
</RelativeLayout>
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.example.ptreinas">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I dont know if you need the second activity (slide1.xml , Slide1.java) let me know
I need your help, thanks in advance .
replace this :
Intent intent = new Intent(this, Slide1.class);
by this:
Intent intent = new Intent(MainActivity.this, Slide1.class);
add your second activity in manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.example.ptreinas">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
//add this line
<activity android:name=".Slide1"/>
</application>

Runtime Error because of ListView id

i'm still new at learning java and this is my first android app and it used to work but now it just shows me an error whenever i try to run this page :
package com.ds.rssreader;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
public class StartingPoint extends ListActivity {
Button Add;
Button Delete;
public static String Menu[];
public static int Menu_counter = 0;
ListView Sites;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.starting);
Add = (Button) findViewById(R.id.Add);
Delete = (Button) findViewById(R.id.Delete);
Sites = (ListView) findViewById(R.id.list);
Add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent OpenAddPage = new Intent("com.ds.rssreader.AddPage");
startActivity(OpenAddPage);
}
});
Delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent OpenDeletePage = new Intent(
"com.ds.rssreader.DeletePage");
startActivity(OpenDeletePage);
}
});
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
and here it's Layout:
<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:padding="25dp"
tools:context="com.ds.rssreader.StartingPoint" >
<Button
android:id="#+id/Add"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Add"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/Delete"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Delete"
tools:ignore="HardcodedText" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/Add"
android:clickable="true"
tools:ignore="HardcodedText" >
</ListView>
</RelativeLayout>
and here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ds.rssreader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:name="android.permission.INTERNET"
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.ds.rssreader.Splash"
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="com.ds.rssreader.StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.StartingPoint" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.AddPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.AddPage" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.DeletePage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.DeletePage" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSFeed"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSFeed" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSHandler"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSHandler" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSItem"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSItem" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
the error causes the program to crash whenever i try to open this page and it says :
E/AndroidRuntime(1085): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ds.rssreader/com.ds.rssreader.StartingPoint}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
and when i try to debug it, it tells me that there is something's source not found
and for the record when i make any other page opens instead of this page it opens without any problems.
REMEMBER GUYS : I'm new in java so don't say big words try to simplify as much as you can
Thanks
In your layout, change:
android:id="#+id/list"
to
android:id="#id/android:list"
and, in your class change:
Sites = (ListView) findViewById(R.id.list);
to
Sites = (ListView) findViewById(android.R.id.list);

ADMOB - Unable to start activity ComponentInfo: java.lang.NullPointerException

I did everything like the tutorial tells the AdMob site, put the layout in XML, imported the path Google Play Sevices and added the lines of code from the tutorial, my application compiles, but no longer opens on your smartphone.
Follows the code.
Classe
package your.CalculoHE.namespace;
import org.apache.cordova.DroidGap;
import com.google.android.gms.ads.*;
import android.os.Bundle;
public class CalculoHoraExtraActivity extends DroidGap {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main);
super.setIntegerProperty("splashscreen", R.drawable.sobreaviso);
super.loadUrl("file:///android_asset/www/index.html", 3000);
// Consultar o AdView como um recurso e carregar uma solicitação.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-*******"
ads:adSize="BANNER"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hora extras"
/>
</LinearLayout>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.CalculoHE.namespace"
android:versionCode="4"
android:versionName="1.2" >
<uses-sdk android:minSdkVersion="9" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity android:configChanges="orientation|keyboardHidden" android:name=".CalculoHoraExtraActivity"
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="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
Try changing:
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
To:
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(new AdRequest());

error emulate player developed in android

I am a beginner in programming for Android, and am making a music and video player, which already programmed much of the program, but when the emulator executes I get the following error:
Unfortunately, FlagPlayer has stopped
I have done many researches on the subject but I can not find anything that solves my problem. I hope you can help me.
here is my main class:
package tcc.etec.FlagPlayer;
import android.R.integer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button btMusica;
private Button btArtista;
private Button btAlbum;
private Button btVideo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
acaobutton();
}
public void acaobutton(){
btMusica = (Button)findViewById(R.id.btmusica);
btMusica.setOnClickListener((OnClickListener) this);
btArtista = (Button)findViewById(R.id.btartista);
btArtista.setOnClickListener((OnClickListener) this);
btAlbum = (Button)findViewById(R.id.btalbuns);
btAlbum.setOnClickListener((OnClickListener) this);
btVideo= (Button)findViewById(R.id.btvideo);
btVideo.setOnClickListener((OnClickListener) this);
}
public void onClick(View v){
if (v.getId()==R.id.btmusica){
Intent intent = new Intent(MainActivity.this, ListaMusicaActivity.class);
}else if (v.getId()==R.id.btartista){
Intent intent = new Intent(MainActivity.this, ListaArtistaActivity.class);
}else if (v.getId()==R.id.btalbuns){
Intent intent = new Intent(MainActivity.this, ListaAlbumActivity.class);
}else if (v.getId()==R.id.btvideo){
Intent intent = new Intent(MainActivity.this, ListaVideoActivity.class);
}
}
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"
tools:context=".MainActivity" >
<Button
android:id="#+id/btmusica"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:text="Musicas" />
<Button
android:id="#+id/btartista"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btmusica"
android:layout_alignBottom="#+id/btmusica"
android:layout_alignParentRight="true"
android:layout_marginRight="14dp"
android:text="Artistas" />
<Button
android:id="#+id/btalbuns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="66dp"
android:text="Albuns" />
<Button
android:id="#+id/btvideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btalbuns"
android:layout_alignBottom="#+id/btalbuns"
android:layout_alignRight="#+id/btartista"
android:text="Videos" />
and AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tcc.etec.FlagPlayer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".tcc.etec.FlagPlayer.activity_main"
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=".tcc.etec.FlagPlayer.ListaMusicaActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".tcc.etec.FlagPlayer.MusicPlayerActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Try to replacing your:
public void acaobutton(){
btMusica = (Button)findViewById(R.id.btmusica);
btMusica.setOnClickListener((OnClickListener) this);
btArtista = (Button)findViewById(R.id.btartista);
btArtista.setOnClickListener((OnClickListener) this);
btAlbum = (Button)findViewById(R.id.btalbuns);
btAlbum.setOnClickListener((OnClickListener) this);
btVideo= (Button)findViewById(R.id.btvideo);
btVideo.setOnClickListener((OnClickListener) this);
}
To:
public void acaobutton(){
btMusica = (Button)findViewById(R.id.btmusica);
btMusica.setOnClickListener((OnClickListener) getBaseContext());
btArtista = (Button)findViewById(R.id.btartista);
btArtista.setOnClickListener((OnClickListener) getBaseContext());
btAlbum = (Button)findViewById(R.id.btalbuns);
btAlbum.setOnClickListener((OnClickListener) getBaseContext());
btVideo= (Button)findViewById(R.id.btvideo);
btVideo.setOnClickListener((OnClickListener) getBaseContext());
}

Categories

Resources